Learn R Programming

stream (version 2.0-1)

DSF_dplyr: 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)

Value

An object of class DSF_dplyr (subclass of DSF and DSD).

Arguments

dsd

A object of class DSD.

func

a dplyr expression.

info

logical; does the function also receive and modify the info columns?

Author

Michael Hahsler

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.

See Also

Other DSF: DSF_Convolve(), DSF_Downsample(), DSF_ExponentialMA(), DSF_Func(), DSF_Scale(), DSF()

Examples

Run this code
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))

}

Run the code above in your browser using DataLab