Hi,

I have a dataset that looks like the one below.

data
plot     plantno.    species
H          31             ABC
D          2               DEF
Y          54             GFE
E          12             ERF
Y          98             FVD
H          4               JKU
J           7               JFG
A          55             EGD
.            .                 .
.            .                 .
.            .                 .

I want to select rows belonging to 7 random plots for 100 times.
(There are 50 plots in total)
So I created a list of 100 vectors, each vector has 7 elements.

samp <- lapply(1:100, function(i) sample(LETTERS))
samp2 <- lapply(samp2, "[", 1:7)

How can I select the 26 plots from 'data' using 'samp'?

samp3 <- sample(LETTERS, 7)
samp4 <- subset(data, plot %in% samp3) # this works
samp5 <- subset(data, plot %in% samp2[[1]]) # this works as well, but
I used a for loop to get it to select 7 plots 100 times.

for (i in nrow(samp2)) {
      samp6 <- subset(data, plot %in% samp2[[i]])
} # this doesn't work


Am I missing something, or is there a better solution?

Thanks.
Kang Min

______________________________________________
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.

Reply via email to