resample_df: Dataframe time resampling.

Description Usage Arguments Value Examples

Description

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.

Usage

1
resample_df(df, t_new)

Arguments

df

Dataframe to be resampled, first column is the timeline

new_t

vector, new timeline

Value

Resampled Dataframe

Examples

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

krzysztofarendt/resampledf documentation built on May 8, 2019, 12:42 p.m.