Description Usage Arguments Value Examples
Function for timeseries data resampling similar to pandas.DataFrame.resample(). It works with both numeric and datetime timelines. The timeline has to be placed in the first column of the dataframe.
1 | resample_df(df, t_new)
|
df |
Dataframe to be resampled, first column is the timeline |
new_t |
vector, new timeline |
Resampled Dataframe
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # Example with numeric timeline
df <- data.frame(time = seq(0, 1800, by = 600))
df$x1 <- 1:nrow(df)
df$x2 <- 1:nrow(df) * 10
new_t <- c(0, 60, 120, 500, 600, 1800)
new_df <- resample_df(df, new_t)
print(head(df))
print(head(new_df))
# Example with datetime timeline
# (works with both POSIXct and POSIXlt)
t1 <- strptime('2019-01-01 00:00:00', format = "%Y-%m-%d %H:%M:%S")
t2 <- strptime('2019-01-01 03:00:00', format = "%Y-%m-%d %H:%M:%S")
df <- data.frame(time = seq(t1, t2, by = 'hour'))
df$x1 <- 1:nrow(df)
df$x2 <- 1:nrow(df) * 10
new_t <- seq(t1, t2, by = 'min')
new_df <- resample_df(df, new_t)
print(head(df))
print(head(new_df))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.