Learn R Programming

stream (version 2.0-1)

DSF_Downsample: Downsample a Data Stream

Description

Creates a new stream that reduces the frequency of a given stream by a given factor.

Usage

DSF_Downsample(dsd = NULL, factor = 1L)

Value

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

Arguments

dsd

The input stream as an DSD object.

factor

the downsampling factor.

Author

Michael Hahsler

See Also

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

Examples

Run this code
# Simple downsampling example
stream <- DSD_Memory(data.frame(rownum = seq(100))) %>% DSF_Downsample(factor = 10)
stream

get_points(stream, n = 2)
get_points(stream, n = 1)
get_points(stream, n = 5)

# DSD_Memory supports getting the remaining points using n = -1
get_points(stream, n = -1)

# Downsample a time series
data(presidents)

stream <- data.frame(
    presidents,
    .time = time(presidents)) %>%
  DSD_Memory()

plot(stream, dim = 1, n = 120, method = "ts")

# downsample by taking only every 3rd data point (quarters)
downsampledStream <- stream %>% DSF_Downsample(factor = 3)

reset_stream(downsampledStream)
plot(downsampledStream, dim = 1, n = 40, method = "ts")

Run the code above in your browser using DataLab