Learn R Programming

enmSdmX (version 1.2.12)

countPoints: Number of points in a "spatial points" object

Description

Returns the number of points in a sf or SpatVector object. This is typically done using either length(x) or nrow(x), depending on whether the object in question has rows or not. This function helps in ambiguous cases, so users need not care if nrow or length is needed.

Usage

countPoints(x, byFeature = FALSE)

Value

Numeric.

Arguments

x

Object of class sf or SpatVector

byFeature

If FALSE, return number of points for all features combined. If TRUE, report number of points per feature.

Examples

Run this code

library(sf)

# lemur occurrence data
data(lemurs)
wgs84 <- getCRS('WGS84')
occs <- lemurs[lemurs$species == 'Eulemur fulvus', ]
occs <- sf::st_as_sf(occs, coords=c('longitude', 'latitude'), crs=wgs84)

countPoints(occs)

Run the code above in your browser using DataLab