Similar in spirit to tidyr::spread(), but does NOT shorten, just widens the data frame -- a tf-column is spread out into many columns containing the functional measurements.

tf_spread(data, value, arg, sep = "_", interpolate = TRUE)

Arguments

data

a data frame with at least one tf-column

value

the name of the tf-column to 'spread'/evaluate. You can supply bare variable names etc., see the dplyr::select() documentation. Also works without this if there's only one tf in data, see examples.

arg

(Semi-)optional. A vector of arg-values on which to evaluate the functions. If not provided, uses the default args. Needs to be specified for f_irreg.

sep

separating character used to create column names for the new columns, defaults to "_" for column names "<name of the tf>_<arg-value>". Set to NULL to get column names that only contain the arg-value.

interpolate

interpolate-argument for evaluating the functional data. Defaults to TRUE, i.e., tfds are inter/extrapolated on unobserved arg-values.

Examples

d <- dplyr::tibble(g = 1:3) d$f <- tf_rgp(3, 11L) tf_spread(d, f)
#> # A tibble: 3 x 12 #> g f_0 f_0.1 f_0.2 f_0.3 f_0.4 f_0.5 f_0.6 f_0.7 f_0.8 f_0.9 #> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1 -0.454 0.161 0.889 1.54 1.67 1.37 0.938 0.771 0.978 1.06 #> 2 2 -0.557 -0.139 0.0270 -0.315 -0.983 -1.20 -0.774 -0.00295 0.543 0.865 #> 3 3 1.17 1.27 0.988 0.183 -0.708 -1.32 -1.32 -1.07 -1.15 -1.36 #> # … with 1 more variable: f_1 <dbl>
tf_spread(d, -g)
#> # A tibble: 3 x 12 #> g f_0 f_0.1 f_0.2 f_0.3 f_0.4 f_0.5 f_0.6 f_0.7 f_0.8 f_0.9 #> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1 -0.454 0.161 0.889 1.54 1.67 1.37 0.938 0.771 0.978 1.06 #> 2 2 -0.557 -0.139 0.0270 -0.315 -0.983 -1.20 -0.774 -0.00295 0.543 0.865 #> 3 3 1.17 1.27 0.988 0.183 -0.708 -1.32 -1.32 -1.07 -1.15 -1.36 #> # … with 1 more variable: f_1 <dbl>
tf_spread(d)
#> # A tibble: 3 x 12 #> g f_0 f_0.1 f_0.2 f_0.3 f_0.4 f_0.5 f_0.6 f_0.7 f_0.8 f_0.9 #> <int> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> #> 1 1 -0.454 0.161 0.889 1.54 1.67 1.37 0.938 0.771 0.978 1.06 #> 2 2 -0.557 -0.139 0.0270 -0.315 -0.983 -1.20 -0.774 -0.00295 0.543 0.865 #> 3 3 1.17 1.27 0.988 0.183 -0.708 -1.32 -1.32 -1.07 -1.15 -1.36 #> # … with 1 more variable: f_1 <dbl>