Description Usage Arguments Value See Also Examples
View source: R/long_wide.R View source: R/longer_dt.R
Analogous function for pivot_longer
in tidyr.
1 2 3 4 5 6 7 8 9 |
data |
A data.frame |
... |
Pattern for unchanged group or unquoted names. Pattern can accept regular expression to match column names. If set 'negate = TRUE', return non-matching columns. |
gathered_name |
name for the measured variable names column. The default name is 'variable'. |
gathered_value |
name for the molten data values column(s). The default name is 'value'. |
group_to_keep |
Group to keep, namely vector of unchanged variables. Can be integer (corresponding id column numbers) or character (id column names) vector. |
negate |
If |
na.rm |
If |
A data.table
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | ## Example 1:
stocks = data.frame(
time = as.Date('2009-01-01') + 0:9,
X = rnorm(10, 0, 1),
Y = rnorm(10, 0, 2),
Z = rnorm(10, 0, 4)
)
stocks
stocks %>%
longer_dt(time)
stocks %>%
longer_dt("ti")
# Example 2:
library(tidyr)
library(tidydt)
billboard %>%
longer_dt(
"wk",
gathered_name = "week",
gathered_value = "rank",
na.rm = TRUE,negate = TRUE
)
# or use:
billboard %>%
longer_dt(
artist,track,date.entered,
gathered_name = "week",
gathered_value = "rank",
na.rm = TRUE,negate = TRUE
)
# or use:
billboard %>%
longer_dt(
group_to_keep = 1:3,
gathered_name = "week",
gathered_value = "rank",
na.rm = TRUE,negate = TRUE
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.