For those working with data and looking to perform data visualization, the concept of vectorization is extremely useful. The short definition of vectorization is that all scalars are actually vectors of length 1. Additionally, functions are vector-aware, so operations like addition natively perform element-wise addition while operations like max natively know how to operate on an array.
seq(from, to, by=1)
A sequence is any regularly spaced set of numbers, such as
To create this integer sequence, use
A decreasing sequence is also possible using
Suppose instead that you want a step size greater than 1. Then explicitly
set the step size with the
seq(1,18, 3). The
by argument can also be used to specify non-integer step sizes,
Note that if the step size does not yield a value coincident with the
to value, the number of elements is rounded up such that
is within the bounds of the resulting array:
rep function replicates the input argument a specified
number of times. For example to create an array of four 1s,
rep(1,4). It is possible to pass an array as an argument,
in which case the result is a single array with all elements
Minima and maxima
Probability and Sampling
sample(x, size, prob=cumsum(rep(1/x,x)))
The sample function provides a way to make repeated draws from a sample space with replacement.
x = seq(1,20) y = sample(x, 100)
You might then want to draw the results using d3.js.
Author: Brian Lee Yung Rowe