read.community reads in file containing occurrence data and returns a sparse matrix.

read.community(file, grids = "grids", species = "species", ...)

Arguments

file

A file name.

grids

Column name of the column containing grid cells.

species

Column name of the column containing the species / taxa names.

...

further arguments passed to or from other methods.

Value

read.community returns a sparse matrix (an object of class "dgCMatrix").

Examples

# \donttest{
df <- data.frame(grids=paste0("g", c(1,1,2,3,3)),
                 species = paste0("sp", c(1,3,2,1,4)))
df
#>   grids species
#> 1    g1     sp1
#> 2    g1     sp3
#> 3    g2     sp2
#> 4    g3     sp1
#> 5    g3     sp4
tmp <- tempfile()
write.csv(df, tmp)
(M <- read.community(tmp) )
#> 3 x 4 sparse Matrix of class "dgCMatrix"
#>    sp1 sp2 sp3 sp4
#> g1   1   .   1   .
#> g2   .   1   .   .
#> g3   1   .   .   1
sparse2long(M)
#>   grids species
#> 1    g1     sp1
#> 2    g3     sp1
#> 3    g2     sp2
#> 4    g1     sp3
#> 5    g3     sp4
unlink(tmp)
# }