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 <- dplyr::as.tbl(data.frame(refund::DTI[1:5, ]$cca[, 1:10])))
tf_gather(d)
tf_gather(d, key = "cca_tf")
tf_gather(d, arg = seq(0, 1, length.out = 10))$cca
(d2 <- dplyr::bind_cols(id = rownames(d), d))
tf_gather(d2, -id) # tf_gather(d2, matches("cca")); tf_gather(d2, -1); etc

fabian-s/tidyfun documentation built on April 14, 2025, 5:16 a.m.