set.seed "sets" the (pseudo-)random number generator in a predictable
state so that you get the same table as I do when running the code,
assuming you don't do any other calls to the RNG in the interim.
123 is kind of traditional as a seed for demonstration purposes, but
in real analyses you could choose any seed favorite number.
--
David.
On Feb 7, 2011, at 9:51 AM, B77S wrote:
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.
______________________________________________
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.
David Winsemius, MD
West Hartford, CT
______________________________________________
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.