[R] Generating and naming multiple time series
jim holtman
jholtman at gmail.com
Wed Aug 5 14:11:17 CEST 2009
Here is one way:
# use 'lapply' to generate your list of 'sets'
sets <- lapply(1:100, function(x){
# create your set of data
runif(100) # test data
})
# put into matrix for 'matplot'
# generates a very busy plot with 100 sets of data
sets.m <- do.call(cbind, sets)
matplot(sets.m, type='l')
On Wed, Aug 5, 2009 at 4:27 AM, Michael
Nahasapeemapetilon<volarb at hotmail.com> wrote:
> Hi,
> I am trying to generate 100 different random walks each containing 500
> variables.
>
> The script I am using to develop one time series:
>> x <- w <- rnorm(500)
>> for (t in 2:500) x[t] <- x[t - 1] + w[t]
>
> >From here I become stuck as I would like to generate a series and name it
> Set1 for the first set, then Set2 for the second....Set(n)
> I have tried rep() to generate the 100 time series and it works, but it
> appears my issue is in naming and storing the sets.
>
> The reason is that I would like to plot all 100 simulated sets onto one
> graph.
>
> If anyone has any hints/ideas for me to explore to achieve this, it is
> greatly appreciated!
>
> Thank you in advance.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Jim Holtman
Cincinnati, OH
+1 513 646 9390
What is the problem that you are trying to solve?
More information about the R-help
mailing list