View source: R/fill-SpatVector.R
fill.SpatVector | R Documentation |
SpatVector
Fills missing values in selected columns using the next or previous entry. This is useful in the common output format where values are not repeated, and are only recorded when they change.
## S3 method for class 'SpatVector'
fill(data, ..., .direction = c("down", "up", "downup", "updown"))
data |
A |
... |
< |
.direction |
Direction in which to fill missing values. Currently either "down" (the default), "up", "downup" (i.e. first down and then up) or "updown" (first up and then down). |
A SpatVector
object.
Implementation of the generic tidyr::fill()
function for SpatVector
.
SpatVector
With grouped SpatVector
created by group_by.SpatVector()
, fill()
will
be applied within each group, meaning that it won't fill across group
boundaries.
tidyr::fill()
Other tidyr verbs for handling missing values:
drop_na.Spat
,
replace_na.Spat
Other tidyr methods:
drop_na.Spat
,
pivot_longer.SpatVector()
,
pivot_wider.SpatVector()
,
replace_na.Spat
library(dplyr)
lux <- terra::vect(system.file("ex/lux.shp", package = "terra"))
# Leave some blanks for demo purporses
lux_blnk <- lux %>%
mutate(NAME_1 = if_else(NAME_1 != NAME_2, NA, NAME_2))
as_tibble(lux_blnk)
# `fill()` defaults to replacing missing data from top to bottom
lux_blnk %>%
fill(NAME_1) %>%
as_tibble()
# direction = "up"
lux_blnk %>%
fill(NAME_1, .direction = "up") %>%
as_tibble()
# Grouping and downup - will restore the initial state
lux_blnk %>%
group_by(ID_1) %>%
fill(NAME_1, .direction = "downup") %>%
as_tibble()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.