[R] repeat a function
Michael Bedward
michael.bedward at gmail.com
Wed Sep 29 06:11:17 CEST 2010
Hi Michael
testdat <- replicate( 50, growth[ sample(nrow(growth), 8, rep=TRUE) ] )
testdat will then be a matrix of 8 x 50 = 400 rows where each lot of 8
is a sample.
Alternatively you can do...
testdat <- replicate( 50, growth[ sample(nrow(growth), 8, rep=TRUE) ],
simplify=FALSE )
Now testdat will be a list of 50 elements, each of which is a sample matrix
Michael
On 29 September 2010 13:49, Michael Larkin <mlarkin at rsmas.miami.edu> wrote:
> I have R randomly sampling my array made up of 2 columns of data. Here is
> my code randomly sampling 5 different rows from my dataset to create a new
> dataset of 8 rows of data:
>
>
>
> testdat<-growth[sample(5,8,replace=T),]
>
>
>
> Now I want to tell R to repeat this function 50 times and give me the
> output. I have been searching the internet and have been unable to figure
> this out. Any advice would be greatly appreciated.
>
>
>
> Mike
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>
More information about the R-help
mailing list