It is a lot prettier than mine too. Thanks Jari. > rrarefy function (x, sample) { if (length(sample) > 1 && length(sample) != nrow(x)) stop("length of 'sample' and number of rows of 'x' do not match") sample <- rep(sample, length = nrow(x)) colnames(x) <- colnames(x, do.NULL = FALSE) nm <- colnames(x) for (i in 1:nrow(x)) { row <- sample(rep(nm, times = x[i, ]), sample[i]) row <- table(row) ind <- names(row) x[i, ] <- 0 x[i, ind] <- row } x }
-- View this message in context: http://r.789695.n4.nabble.com/Subsampling-out-of-site-abundance-matrix-tp3263148p3276735.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.