DSF_dplyr | R Documentation |
Applies dplyr transformations to a data stream.
DSF_dplyr(dsd = NULL, func = NULL, info = FALSE)
dsd |
A object of class DSD. |
func |
a dplyr expression. |
info |
logical; does the function also receive and modify the info columns? |
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:
dplyr::select()
dplyr::mutate()
dplyr::rename()
dplyr::transmute()
dplyr::filter()
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.
An object of class DSF_dplyr
(subclass of DSF and DSD).
Michael Hahsler
Other DSF:
DSF_Convolve()
,
DSF_Downsample()
,
DSF_ExponentialMA()
,
DSF_Func()
,
DSF_Scale()
,
DSF()
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)) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.