View source: R/dt_modification.R
reduce_freq | R Documentation |
In a time series dataset, there is a time difference between one row and the next one. This function reduces the number of rows from its current frequency to the desired one by averaging batches of rows. Instead of the frequency in Hz, the number of seconds between rows is asked (Hz = 1/s).
reduce_freq(dt, obj_freq, curr_freq, id_var = NULL)
dt |
the original data.table |
obj_freq |
the desired number of seconds between rows |
curr_freq |
the number of seconds between rows in the original dataset |
id_var |
optional variable that labels different time series in a dataset, to avoid averaging values from different processes |
the data.table with the desired frequency
# Let's assume that the dataset has a frequency of 4Hz, 0.25 seconds between rows
dt <- dbnR::motor
dim(dt)
# Let's change the frequency to 2Hz, 0.5 seconds between rows
dt <- reduce_freq(dt, obj_freq = 0.5, curr_freq = 0.2)
dim(dt)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.