Various constructor and conversion methods.
tfd.data.frame
uses the first 3 columns of data
for function information by default:
(ìd
, arg
, value
)
tfd.list
accepts a list of vectors of identical lengths
containing evaluations or a list of 2column matrices/data.frames with
arg
in the first and evaluations in the second column
return class prototype when argument to tfd() is NULL or not a recongised class
as.tfd(data, ...) as.tfd_irreg(data, ...) # S3 method for tfd as.data.frame( x, row.names = NULL, optional = FALSE, arg = NULL, interpolate = FALSE, ... ) # S3 method for tfd as.matrix(x, arg = NULL, interpolate = FALSE, ...) tfd(data, ...) # S3 method for matrix tfd( data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, resolution = NULL, ... ) # S3 method for numeric tfd( data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, resolution = NULL, ... ) # S3 method for data.frame tfd( data, id = 1, arg = 2, value = 3, domain = NULL, evaluator = tf_approx_linear, resolution = NULL, ... ) # S3 method for list tfd( data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, resolution = NULL, ... ) # S3 method for tf tfd(data, arg = NULL, domain = NULL, evaluator = NULL, resolution = NULL, ...) # S3 method for default tfd( data, arg = NULL, domain = NULL, evaluator = tf_approx_linear, resolution = NULL, ... )
data  a 

...  not used in 
x  an 
row.names  not used 
optional  not used 
arg 

interpolate  should functions be evaluated (i.e., inter/extrapolated)
for values in 
domain  range of the 
evaluator  a function accepting arguments 
resolution  resolution of the evaluation grid. See details for 
id  The name/number of the column defining which data belong to which function. 
value  The name/number of the column containing the function evaluations. 
an tfd
object (or a data.frame
/matrix
for the conversion functions, obviously.)
evaluator
: must be the (quoted or bare) name of a
function(x, arg, evaluations)
that returns
the functions' (tf_approximated/interpolated) values at locations x
based on
the evaluations
available at locations arg
.
Available evaluator
functions:
tf_approx_linear
for linear interpolation without extrapolation (i.e.,
zoo::na.approx()
with na.rm = FALSE
)  this is the default,
tf_approx_spline
for cubic spline interpolation, (i.e., zoo::na.spline()
with na.rm = FALSE
),
tf_approx_fill_extend
for linear interpolation and constant extrapolation
(i.e., zoo::na.fill()
with fill = "extend"
)
tf_approx_locf
for "last observation carried forward" (i.e.,
zoo::na.locf()
with na.rm = FALSE
and
tf_approx_nocb
for "next observation carried backward" (i.e.,
zoo::na.locf()
with na.rm = FALSE, fromLast = TRUE
).
See tidyfun:::zoo_wrapper
and tidyfun:::tf_approx_linear
, which is simply
zoo_wrapper(zoo::na.tf_approx, na.rm = FALSE)
, for examples of implementations of
this.
resolution
: arg
values that are equivalent up to this difference are
treated as identical. E.g., if an evaluation of $f(t)$ is available at $t=1$
and a function value is requested at $t = 1.01$, $f(1)$ will be returned if
resolution
< .01. By default, resolution will be set to an integervalued power
of 10 one smaller than smallest difference between adjacent
argvalues rounded down to an integervalued power
of 10: e.g., if the smallest difference between consecutive
argvalues is between $0.1 and 0.9999$, the resolution will be $0.01$, etc.
In code: 10^(floor(log10(min(diff(<arg>)))  1)
#turn irregular to regular tfd #TODO: add extra function/verb for this (f < c(tf_rgp(1, arg = seq(0,1,l=11)), tf_rgp(1, arg = seq(0,1,l=21))))#> Warning: concatenating functions on different grids.#> Warning: inputs have different resolutions, result has resolution =0.01#> tfd[2] on (0,1) based on 11 to 21 (mean: 16) evaluations each #> inter/extrapolation by tf_approx_linear #> [1]: ( 0.0, 0.342);( 0.1, 0.086);( 0.2, 0.425); ... #> [2]: (0.00,0.104);(0.05,0.156);(0.10,0.075); ...#> tfd[2] on (0,1) based on 21 evaluations each #> interpolation by tf_approx_linear #> [1]: (0.00, 0.342);(0.05, 0.214);(0.10, 0.086); ... #> [2]: (0.00,0.104);(0.05,0.156);(0.10,0.075); ...#> tfd[2] on (0,1) based on 43 to 93 (mean: 68) evaluations each #> inter/extrapolation by tf_approx_linear #> 1001_1: (0.000,0.49);(0.011,0.52);(0.022,0.54); ... #> 1002_1: ( 0.22,0.44);( 0.24,0.48);( 0.26,0.48); ...#> Warning: 5 evaluations were NA, returning irregular tfd.#> tfd[2] on (0,1) based on 16 to 21 (mean: 18) evaluations each #> inter/extrapolation by tf_approx_linear #> 1001_1: (0.00,0.49);(0.05,0.62);(0.10,0.64); ... #> 1002_1: (0.25,0.48);(0.30,0.57);(0.35,0.65); ...