
Last chance! 50% off unlimited learning
Sale ends in
Gather columns into key-value pairs.
# S3 method for tbl_ts
gather(data, key = "key", value = "value", ...,
na.rm = FALSE, convert = FALSE, factor_key = FALSE)
A tbl_ts
.
Names of new key and value columns, as strings or symbols.
This argument is passed by expression and supports
quasiquotation (you can unquote strings
and symbols). The name is captured from the expression with
rlang::quo_name()
(note that this kind of interface where
symbols do not represent actual objects is now discouraged in the
tidyverse; we support it here for backward compatibility).
Names of new key and value columns, as strings or symbols.
This argument is passed by expression and supports
quasiquotation (you can unquote strings
and symbols). The name is captured from the expression with
rlang::quo_name()
(note that this kind of interface where
symbols do not represent actual objects is now discouraged in the
tidyverse; we support it here for backward compatibility).
A selection of columns. If empty, all variables are
selected. You can supply bare variable names, select all
variables between x and z with x:z
, exclude y with -y
. For
more options, see the dplyr::select()
documentation. See also
the section on selection rules below.
If TRUE
, will remove rows from output where the
value column in NA
.
If TRUE
will automatically run
type.convert()
on the key column. This is useful if the column
names are actually numeric, integer, or logical.
If FALSE
, the default, the key values will be
stored as a character vector. If TRUE
, will be stored as a factor,
which preserves the original ordering of the columns.
# NOT RUN {
# example from tidyr
stocks <- tsibble(
time = as.Date('2009-01-01') + 0:9,
X = rnorm(10, 0, 1),
Y = rnorm(10, 0, 2),
Z = rnorm(10, 0, 4)
)
stocks %>% gather(stock, price, -time)
# }
Run the code above in your browser using DataLab