I think that you want:

replicate(5, growth[sample(9,12,replace=T),], simplify = FALSE)


On Wed, Sep 29, 2010 at 3:19 PM, Michael Larkin <mlarkin@rsmas.miami.edu>wrote:

> I am trying to get R to resample my dataset of two columns of age and
> length
> data for fish.  I got it to work, but it is not resampling every replicate.
> Instead, it resamples my data once and then repeated it 5 times.
>
> Here is my dataset of 9 fish samples with an age and length for each one:
> Age     Length
> 2       200
> 5       450
> 6       600
> 7       702
> 8       798
> 5       453
> 4       399
> 1       120
> 2       202
>
>
> Here is my code which resamples my data to produce up to 9 different
> samples
> and creates a new dataset of 12 samples:
>
> testdat<-growth[sample(9,12,replace=T),]
>
>
> Now I want R to repeat this procedure 5 times. Here is my code:
>
>
> testdat2 <- replicate(5, sample(testdat), simplify=F)
> testdat2
>
> Here is my output showing that it did it once and then just repeated the
> values:
>
>
> > testdat2
> [[1]]
>    Age Length
> 1     2    200
> 9     2    202
> 8     1    120
> 5     8    798
> 4     7    702
> 6     5    453
> 1.1   2    200
> 4.1   7    702
> 4.2   7    702
> 5.1   8    798
> 4.3   7    702
> 6.1   5    453
>
> [[2]]
>    Age Length
> 1     2    200
> 9     2    202
> 8     1    120
> 5     8    798
> 4     7    702
> 6     5    453
> 1.1   2    200
> 4.1   7    702
> 4.2   7    702
> 5.1   8    798
> 4.3   7    702
> 6.1   5    453
>
> [[3]]
>    Age Length
> 1     2    200
> 9     2    202
> 8     1    120
> 5     8    798
> 4     7    702
> 6     5    453
> 1.1   2    200
> 4.1   7    702
> 4.2   7    702
> 5.1   8    798
> 4.3   7    702
> 6.1   5    453
>
> [[4]]
>    Length Age
> 1      200   2
> 9      202   2
> 8      120   1
> 5      798   8
> 4      702   7
> 6      453   5
> 1.1    200   2
> 4.1    702   7
> 4.2    702   7
> 5.1    798   8
> 4.3    702   7
> 6.1    453   5
>
> [[5]]
>    Length Age
> 1      200   2
> 9      202   2
> 8      120   1
> 5      798   8
> 4      702   7
> 6      453   5
> 1.1    200   2
> 4.1    702   7
> 4.2    702   7
> 5.1    798   8
> 4.3    702   7
> 6.1    453   5
>
>
> Any advice on how to get R to resample each time would be greatly
> appreciated?
>
> Mike
>
> ______________________________________________
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

