tf_gather: Gather all columns representing functional measurements into...

View source: R/tidyr.R

tf_gatherR Documentation

Gather all columns representing functional measurements into a tfd-object

Description

Similar in spirit to tidyr::gather(), but does NOT put the values in the gathered columns into one very long "value"-column while labeling the different original columns in a very long "key"-column – instead it creates a tfd-column containing the functional measurements of the columns given in ....

Usage

tf_gather(
  data,
  ...,
  key = ".tfd",
  arg = NULL,
  domain = NULL,
  evaluator = tf_approx_linear
)

Arguments

data

a data frame – note that dplyr does not handle matrix columns well, if data contains more than one of those, tf_gather will fail...

...

A selection of columns to collect as a tfd object. Each column represents measurements of a functional variable at a specific arg-val. Can also be the name of a matrix-valued column, but see above. 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.

key

the name of the created tfd-column. Defaults to ".tfd", but the function will try to guess the name based on the column names of the gathered columns in this case. If a common prefix of all column names is found, this is used instead. You also get a message about this.

arg

optional. Argument values for the functions. If not provided, will be guessed from the column names as well. See also tf::tfd().

domain

optional. Range of possible arg-values. See tf::tfd() for details.

evaluator

optional. A function accepting arguments x, arg, evaluations. See tf::tfd() for details.

Value

a modified data.frame with a tfd column replacing the ....

See Also

dplyr::select()

Other tidyfun data wrangling functions: tf_evaluate.data.frame(), tf_nest(), tf_spread(), tf_unnest()

Examples

d <- tf_spread(growth[1:5, ]) |> dplyr::mutate(id = 1:dplyr::n())
dplyr::glimpse(d)
# tidyselect syntax for column selection:
tf_gather(d, starts_with("height"))
tf_gather(d, height_1:height_18)
tf_gather(d, -gender, -id)
# custom key name and arg values:
tf_gather(d, starts_with("height"), key = "height")
tf_gather(d, starts_with("height"), arg = seq(0, 1, length.out = 31))

tidyfun documentation built on April 24, 2026, 5:06 p.m.