long2sparse: Conversion of community data

Description Usage Arguments Value Examples

View source: R/sample2sparsematrix.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
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)

phyloregion documentation built on May 1, 2021, 9:06 a.m.