[R] resampling issue

Michael Larkin mlarkin at rsmas.miami.edu
Wed Sep 29 20:19:42 CEST 2010


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



More information about the R-help mailing list