Conversion of community data
These functions convert a community data to compressed sparse matrix, dense matrix and long format (e.g. species records).
long2sparse(x, grids = "grids", species = "species") sparse2long(x) dense2sparse(x) sparse2dense(x) long2dense(x) dense2long(x)
x
: A community data which one wants to transformgrids
: column name of the column containing grid cellsspecies
: column name of the column containing the species / taxa namesA compressed sparse community matrix of sites by species
data(africa) africa$comm[1:5, 1:20] long <- sparse2long(africa$comm) long[1:5, ] sparse <- long2sparse(long) all.equal(africa$comm, sparse) dense_comm <- matrix(c(1,0,1,1,0,0, 1,0,0,1,1,0, 1,1,1,1,1,1, 0,0,1,1,0,1), 6, 4, dimnames=list(paste0("g",1:6), paste0("sp", 1:4))) dense_comm sparse_comm <- dense2sparse(dense_comm) sparse_comm sparse2long(sparse_comm)
Useful links