long2sparse function

Conversion of community data

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)

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

Returns

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)