[R] Nested for loop

S Ellison S.Ellison at LGCGroup.com
Tue Aug 8 14:15:47 CEST 2017


> The code I've attached works for a population of 400 and samples 100 times.
> I'd like to extend this to 300 samples and 3 populations. So, the x-axis would
> range from 0-300 samples.
> 
> What I'm having trouble with is finding a way to change the population mid-
> way through the function. I want samples 1-100 to be taken from a
> population of 400, samples 101-200 to be taken from a sample of 800 and
> samples 201-300 from a population of 300. The end result should look
> something like a heart rate monitor.

You could write your function to take a list of either subpopulations or sets of population parameters, lapply your simulation generator over the list and (assuming the output from each of those is a vector) use c(that.list, recursive=TRUE) to concatenate the resulting list of vectors into a single vector.


S Ellison


*******************************************************************
This email and any attachments are confidential. Any use...{{dropped:8}}



More information about the R-help mailing list