dfilter | R Documentation |
Filter entries of a vector d
of class numeric
, integer
, Date
, or POSIXt
according to maximal distance max.dist
.
dfilter(
d,
min.dist = 0,
max.dist = Inf,
temporal.unit = c("days", "seconds", "minutes", "hours", "weeks", "years"),
which.chunk = "all"
)
d |
a |
min.dist |
|
max.dist |
|
temporal.unit |
only applies, if |
which.chunk |
controls output and display of chunks satisfying the restriction imposed by |
depending on which.chunk
a logical
("biggest", "first", and "random") labeling
entries in d
to be retained or a data.frame
("all") containing retained entries and the chunk number.
# test data
set.seed(1)
test <- data.frame(group = sample(letters[1:4], 20, TRUE),
pos = runif(20, 0, 100),
time = as.POSIXct(runif(20, 0, as.numeric(Sys.time())),
origin = as.POSIXct("1970-01-01 00:00.00 UTC")))
# indicate first chunk satisfying the condition set by max.dist
dfilter(test$pos, max.dist = 15, which.chunk = "first")
# show all chunks
dfilter(test$pos, max.dist = 15, which.chunk = "all")
# apply in a grouped tibble
test %>% group_by(group) %>% filter(dfilter(time, max.dist = 1000, which.chunk = "first"))
# please note that in a grouped tibble, you cannot use dfilter inside filter()
test %>% group_by(group) %>% group_modify(~ dfilter(.x[, "pos"], max.dist = 15, which.chunk = "all"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.