| tf_where {tf} | R Documentation |
Find out where functional data fulfills certain conditions.
Description
tf_where allows to define a logical expression about the function values
and returns the argument values for which that condition is true.
tf_anywhere is syntactic sugar for tf_where with return = "any" to
get a logical flag for each function if the condition is TRUE anywhere,
see below.
Usage
tf_where(f, cond, return = c("all", "first", "last", "range", "any"), arg)
tf_anywhere(f, cond, arg)
Arguments
f |
a |
cond |
a logical expression about |
return |
for each entry in |
arg |
optional |
Details
Entries in f that do not fulfill cond anywhere yield numeric(0).
cond is evaluated as a base::subset()-statement on a data.frame
containing a single entry in f with columns arg and value, so most
of the usual dplyr tricks are available as well, see examples.
Any condition evaluates to NA on NA-entries in f.
Value
depends on return:
-
return = "any", i.e,anywhere: a logical vector of the same length asf. -
return = "all": a list of vectors of the same length asf, with empty vectors for the functions that never fulfill thecondition. -
return = "range": a data frame with columns "begin" and "end". else, a numeric vector of the same length as
fwithNAfor entries offthat nowhere fulfill thecondition.
Examples
lin <- 1:4 * tfd(seq(-1, 1, length.out = 11), seq(-1, 1, length.out = 11))
tf_where(lin, value %inr% c(-1, 0.5))
tf_where(lin, value %inr% c(-1, 0.5), "range")
a <- 1
tf_where(lin, value > a, "first")
tf_where(lin, value < a, "last")
tf_where(lin, value > 2, "any")
tf_anywhere(lin, value > 2)
set.seed(4353)
f <- tf_rgp(5, 11)
plot(f, pch = as.character(1:5), points = TRUE)
tf_where(f, value == max(value))
# where is the function increasing/decreasing?
tf_where(f, value > dplyr::lag(value, 1, value[1]))
tf_where(f, value < dplyr::lead(value, 1, tail(value, 1)))
# where are the (interior) extreme points (sign changes of `diff(value)`)?
tf_where(
f,
sign(c(diff(value)[1], diff(value))) !=
sign(c(diff(value), tail(diff(value), 1)))
)
# where in its second half is the function positive?
tf_where(f, arg > 0.5 & value > 0)
# does the function ever exceed?
tf_anywhere(f, value > 1)