to_spatial: Convert a site-by-variable matrix into a SpatRaster or sf...

View source: R/utils.R

to_spatialR Documentation

Convert a site-by-variable matrix into a SpatRaster or sf object

Description

Convert a site-by-variable matrix into a SpatRaster or sf object

Usage

to_spatial(m, template)

Arguments

m

Matrix or vector with the same number of rows as sites in template. Note that ps$comm contains only occupied sites and must be expanded with ps_expand() before passing to this function.

template

SpatRaster layer with number of cells equal to the number of rows in m, or sf data frame with same number of rows as m.

Value

SpatRaster with a layer for every column in m, or sf data frame with a variable for every column in m, depending on the data type of template.

Examples

ps <- moss()
# ps$comm contains only occupied sites, so expand before converting:
to_spatial(ps_expand(ps, ps$comm[, 1:5]), ps$spatial)

phylospatial documentation built on April 4, 2026, 1:07 a.m.