View source: R/sample2sparsematrix.R
long2sparse | R Documentation |
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 transform |
grids |
column name of the column containing grid cells |
species |
column name of the column containing the species / taxa names |
A 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.