DSF_dplyr {stream} | R Documentation |
Apply a dplyr Transformation to a Data Stream
Description
Applies dplyr transformations to a data stream.
Usage
DSF_dplyr(dsd = NULL, func = NULL, info = FALSE)
Arguments
dsd |
A object of class DSD. |
func |
a dplyr expression. |
info |
logical; does the function also receive and modify the info columns? |
Details
dplyr needs to be installed and loaded with library(dplyr)
before DSF_dplyr
can be used.
Since streams are processed one point or block at a time, only dplyr::dplyr operations that work on individual rows are allowed on streams. Examples are:
Summary functions can be used, but will only be applied to the requested part of the stream of length n
.
DSF_dplyr()
calls the function using points %>% <func>
and multiple dplyr
functions can be applied by
using %>%
between them.
Value
An object of class DSF_dplyr
(subclass of DSF and DSD).
Author(s)
Michael Hahsler
See Also
Other DSF:
DSF()
,
DSF_Convolve()
,
DSF_Downsample()
,
DSF_ExponentialMA()
,
DSF_FeatureSelection()
,
DSF_Func()
,
DSF_Scale()
Examples
if (require(dplyr)) {
library(dplyr)
stream <- DSD_Gaussians(k = 3, d = 3)
plot(stream, xlim = c(0, 1), ylim = c(0, 1))
# 1. Select only columns X1 and X2
# 2. filter points by X1 > .5 (Note that the info columns also need to be filtered!)
# 3. Add a sum columns
stream2 <- stream %>%
DSF_dplyr(select(X1, X2)) %>%
DSF_dplyr(filter(X1 > .5), info = TRUE) %>%
DSF_dplyr(mutate(Xsum = X1 + X2))
stream2
# Note: you get fewer points because of the filter operation.
get_points(stream2, n = 10)
plot(stream2, xlim = c(0, 1), ylim = c(0, 1))
}