Skip to contents

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.

Usage

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

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. Should be specified for tf_irreg, otherwise all observed gridpoint are used for every function.

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 FALSE, i.e., tfds are not inter/extrapolated on unobserved arg-values.

Value

a wider dataframe with the tf-column spread out into many columns each containing the functional measurements for one arg-value.

See also

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

Examples

d <- dplyr::tibble(g = 1:3)
d$f <- tf_rgp(3, 11L)
tf_spread(d, f)
#> # A tibble: 3 × 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  1.37   1.51   1.30   0.705  0.216  0.220   0.601  1.10   1.49   1.43 
#> 2     2  0.352  0.432 -0.216 -1.09  -1.54  -1.52   -1.05  -0.211  0.696  1.41 
#> 3     3 -1.05  -1.06  -0.899 -0.646 -0.322 -0.0681 -0.211 -0.621 -0.771 -0.741
#> # ℹ 1 more variable: f_1 <dbl>
tf_spread(d, -g)
#> # A tibble: 3 × 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  1.37   1.51   1.30   0.705  0.216  0.220   0.601  1.10   1.49   1.43 
#> 2     2  0.352  0.432 -0.216 -1.09  -1.54  -1.52   -1.05  -0.211  0.696  1.41 
#> 3     3 -1.05  -1.06  -0.899 -0.646 -0.322 -0.0681 -0.211 -0.621 -0.771 -0.741
#> # ℹ 1 more variable: f_1 <dbl>
tf_spread(d)
#> # A tibble: 3 × 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  1.37   1.51   1.30   0.705  0.216  0.220   0.601  1.10   1.49   1.43 
#> 2     2  0.352  0.432 -0.216 -1.09  -1.54  -1.52   -1.05  -0.211  0.696  1.41 
#> 3     3 -1.05  -1.06  -0.899 -0.646 -0.322 -0.0681 -0.211 -0.621 -0.771 -0.741
#> # ℹ 1 more variable: f_1 <dbl>