pivot_longer_spec | R Documentation |
This is a low level interface to pivoting, inspired by the cdata package, that allows you to describe pivoting with a data frame.
pivot_longer_spec(
data,
spec,
...,
cols_vary = "fastest",
names_repair = "check_unique",
values_drop_na = FALSE,
values_ptypes = NULL,
values_transform = NULL,
error_call = current_env()
)
build_longer_spec(
data,
cols,
...,
names_to = "name",
values_to = "value",
names_prefix = NULL,
names_sep = NULL,
names_pattern = NULL,
names_ptypes = NULL,
names_transform = NULL,
error_call = current_env()
)
data |
A data frame to pivot. |
spec |
A specification data frame. This is useful for more complex pivots because it gives you greater control on how metadata stored in the column names turns into columns in the result. Must be a data frame containing character |
... |
These dots are for future extensions and must be empty. |
cols_vary |
When pivoting
|
names_repair |
What happens if the output has invalid column names?
The default, |
values_drop_na |
If |
error_call |
The execution environment of a currently
running function, e.g. |
cols |
< |
names_to |
A character vector specifying the new column or columns to
create from the information stored in the column names of
|
values_to |
A string specifying the name of the column to create
from the data stored in cell values. If |
names_prefix |
A regular expression used to remove matching text from the start of each variable name. |
names_sep , names_pattern |
If
If these arguments do not give you enough control, use
|
names_ptypes , values_ptypes |
Optionally, a list of column name-prototype
pairs. Alternatively, a single empty prototype can be supplied, which will
be applied to all columns. A prototype (or ptype for short) is a
zero-length vector (like |
names_transform , values_transform |
Optionally, a list of column
name-function pairs. Alternatively, a single function can be supplied,
which will be applied to all columns. Use these arguments if you need to
change the types of specific columns. For example, If not specified, the type of the columns generated from |
# See vignette("pivot") for examples and explanation
# Use `build_longer_spec()` to build `spec` using similar syntax to `pivot_longer()`
# and run `pivot_longer_spec()` based on `spec`.
spec <- relig_income %>% build_longer_spec(
cols = !religion,
names_to = "income",
values_to = "count"
)
spec
pivot_longer_spec(relig_income, spec)
# Is equivalent to:
relig_income %>% pivot_longer(
cols = !religion,
names_to = "income",
values_to = "count"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.