[R] Subsampling out of site*abundance matrix

B77S bps0002 at auburn.edu
Tue Feb 8 21:34:55 CET 2011


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.



More information about the R-help mailing list