long2sparse: Conversion of community data

View source: R/sample2sparsematrix.R

long2sparseR Documentation

Conversion of community data

Description

These functions convert a community data to compressed sparse matrix, dense matrix and long format (e.g. species records).

Usage

long2sparse(x, grids = "grids", species = "species")

sparse2long(x)

dense2sparse(x)

sparse2dense(x)

long2dense(x)

dense2long(x)

Arguments

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

Value

A compressed sparse community matrix of sites by species

Examples

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)


darunabas/phyloregion documentation built on Oct. 27, 2024, 10:01 p.m.