View source: R/pivot-wide-SpatVector.R
pivot_wider.SpatVector | R Documentation |
SpatVector
from long to widepivot_wider()
"widens" a SpatVector
, increasing the number of columns and
decreasing the number of rows. The inverse transformation is
pivot_longer.SpatVector()
.
## S3 method for class 'SpatVector'
pivot_wider(
data,
...,
id_cols = NULL,
id_expand = FALSE,
names_from = "name",
names_prefix = "",
names_sep = "_",
names_glue = NULL,
names_sort = FALSE,
names_vary = "fastest",
names_expand = FALSE,
names_repair = "check_unique",
values_from = "value",
values_fill = NULL,
values_fn = NULL,
unused_fn = NULL
)
data |
A |
... |
Additional arguments passed on to methods. |
id_cols |
< Defaults to all columns in Note that " |
id_expand |
Should the values in the |
names_from , values_from |
< If |
names_prefix |
A regular expression used to remove matching text from the start of each variable name. |
names_sep |
If |
names_glue |
Instead of |
names_sort |
Should the column names be sorted? If |
names_vary |
When
|
names_expand |
Should the values in the |
names_repair |
What happens if the output has invalid column names?
The default, |
values_fill |
Optionally, a (scalar) value that specifies what each
This can be a named list if you want to apply different fill values to different value columns. |
values_fn |
Optionally, a function applied to the value in each cell
in the output. You will typically use this when the combination of
This can be a named list if you want to apply different aggregations
to different |
unused_fn |
Optionally, a function applied to summarize the values from
the unused columns (i.e. columns not identified by The default drops all unused columns from the result. This can be a named list if you want to apply different aggregations to different unused columns.
This is similar to grouping by the |
A SpatVector
object.
Implementation of the generic tidyr::pivot_wider()
function.
SpatVector
The geometry column has a sticky behavior. This means that the result would
have always the geometry of data
.
tidyr::pivot_wider()
Other tidyr verbs for pivoting:
pivot_longer.SpatVector()
Other tidyr methods:
drop_na.Spat
,
fill.SpatVector()
,
pivot_longer.SpatVector()
,
replace_na.Spat
library(dplyr)
library(tidyr)
library(ggplot2)
cyl <- terra::vect(system.file("extdata/cyl.gpkg", package = "tidyterra"))
# Add extra row with info
xtra <- cyl %>%
slice(c(2, 3)) %>%
mutate(
label = "extra",
value = TRUE
) %>%
rbind(cyl, .) %>%
glimpse()
# Pivot by geom
xtra %>%
pivot_wider(
id_cols = iso2:name, values_from = value,
names_from = label
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.