pivot_longer {poorman} | R Documentation |
Pivot data from wide to long
Description
pivot_longer()
"lengthens" data, increasing the number of rows and decreasing the number of columns. The inverse
transformation is pivot_wider()
.
Usage
pivot_longer(
data,
cols,
names_to = "name",
names_prefix = NULL,
names_sep = NULL,
names_pattern = NULL,
values_to = "value",
values_drop_na = FALSE,
...
)
Arguments
data |
|
cols |
< |
names_to |
|
names_prefix |
|
names_sep , names_pattern |
|
values_to |
|
values_drop_na |
|
... |
Additional arguments passed on to methods. |
Value
A data.frame
.
Examples
wide_data <- data.frame(replicate(5, rnorm(10)))
# Customizing the names
pivot_longer(
data = wide_data,
cols = c(1, 2),
names_to = "Column",
values_to = "Numbers"
)