Learn R Programming

tidyterra (version 0.1.0)

drop_na: Drop attributes of SpatVector objects containing missing values

Description

drop_na() method drops geometries where any attribute specified by ... contains a missing value.

Usage

# S3 method for SpatVector
drop_na(data, ...)

Arguments

data

A SpatVector created with terra::vect().

...

tidy-select Attributes to inspect for missing values. If empty, all attributes are used.

Value

A Spat* object of the same class than .data. See Methods.

Methods

Implementation of the generic tidyr::drop_na() function.

SpatVector

The implementation of this method is performed on a by-attribute basis, meaning that NAs are assessed on the attributes (columns) of each vector (rows). The result is a SpatVector with potentially less geometries than the input

See Also

tidyr::drop_na(). [Questioning] A method for SpatRaster is also available, see drop_na.SpatRaster().

Other tidyr.methods: replace_na()

Examples

Run this code
# NOT RUN {
library(terra)

f <- system.file("extdata/cyl.gpkg", package = "tidyterra")

v <- terra::vect(f)

# Add NAs
v <- v %>% mutate(iso2 = ifelse(cpro <= "09", NA, cpro))

# Init
plot(v, col = "red")

# Mask with lyr.1
v %>%
  drop_na(iso2) %>%
  plot(col = "red")
# }

Run the code above in your browser using DataLab