[R] Subsampling out of site*abundance matrix
B77S
bps0002 at auburn.edu
Mon Feb 7 15:51:18 CET 2011
Also, I really appreciate you explaining why you used factor. I'm still not
quite sure what set.seed does (i read ?set.seed) or why you chose 123... but
it and the function below work, so that is all that matters. :)
randSub <- function(L1, s.size)
{
set.seed(123)
samptbl <- apply(L1, 1, function(x) sample(colnames(L1), s.size, prob=x,
replace=TRUE) )
sampdf <- as.data.frame(samptbl)
sampdf1 <-vector("list")
for(i in 1:nrow(L1))
{
sampdf1[[i]] <- factor(sampdf[[i]], levels= colnames(L1))
}
out <- t(sapply(sampdf1, table))
}
--
View this message in context: http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3264251.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list