Generating random time series objects in R
We are going to generate some random time series objects in base R. Doing this is very simple as base R comes with some distribution functions already packed in. We will make use of the random normal distribution by making calls to the rnorm()
function. This function has three parameters to provide arguments to:
n
: The number of points to be generatedmean
: The mean of the distribution, with a default of 0sd
: The standard deviation of the distribution, with the default being 1
Let’s go ahead and generate our first random vector. We will call it x
:
# Generate a Random Time Series # Set seed to make results reproducible set.seed(123) # Generate Random Points using a gaussian distribution with mean 0 and sd = 1 n <- 25 x <- rnorm(n) head(x) [1] -0.56047565 -0.23017749 1.55870831 0.07050839 0.12928774 1.71506499
In the preceding code, we did the following:
...