bind_cols.SpatVector {tidyterra} | R Documentation |
Bind multiple SpatVector
sf
and data frames objects by column
Description
Bind any number of SpatVector
, data frames and sf
object by column,
making a wider result. This is similar to do.call(cbind, dfs)
.
Where possible prefer using a join to combine
SpatVector
and data frames objects. bind_spat_cols()
binds the rows in
order in which they appear so it is easy to create meaningless results
without realizing it.
Usage
bind_spat_cols(
...,
.name_repair = c("unique", "universal", "check_unique", "minimal")
)
Arguments
... |
Objects to combine. The first argument should be a |
.name_repair |
One of |
Value
A SpatVector
with the corresponding columns. The geometry and CRS
would correspond to the the first SpatVector
of ...
.
terra equivalent
cbind()
method
Methods
Implementation of the dplyr::bind_rows()
function for
SpatVector
objects. Note that for the second and subsequent arguments on
...
the geometry would not be cbind
ed, and only the data frame (-ish)
columns would be kept.
See Also
Other dplyr verbs that operate on pairs Spat*
/data.frame:
bind_rows.SpatVector
,
filter-joins.SpatVector
,
mutate-joins.SpatVector
Other dplyr methods:
arrange.SpatVector()
,
bind_rows.SpatVector
,
count.SpatVector()
,
distinct.SpatVector()
,
filter-joins.SpatVector
,
filter.Spat
,
glimpse.Spat
,
group-by.SpatVector
,
mutate-joins.SpatVector
,
mutate.Spat
,
pull.Spat
,
relocate.Spat
,
rename.Spat
,
rowwise.SpatVector()
,
select.Spat
,
slice.Spat
,
summarise.SpatVector()
Examples
library(terra)
sv <- vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
df2 <- data.frame(letters = letters[seq_len(nrow(sv))])
# Data frame
bind_spat_cols(sv, df2)
# Another SpatVector
bind_spat_cols(sv[1:2, ], sv[3:4, ])
# sf objects
sfobj <- sf::read_sf(system.file("shape/nc.shp", package = "sf"))
bind_spat_cols(sv[1:9, ], sfobj[1:9, ])
# Mixed
end <- bind_spat_cols(sv, sfobj[seq_len(nrow(sv)), 1:2], df2)
end
glimpse(end)
# Row sizes must be compatible when column-binding
try(bind_spat_cols(sv, sfobj))