Description Usage Arguments Details Value Examples
A less efficient implementation of roll_mean that
can roll over inconsistently sampled data by a specified time
window.
1  | roll_mean.time(x, time, window, na.rm = TRUE)
 | 
x | 
 numeric vector to be rolled over.  | 
time | 
 numeric vector of sampling time values.  | 
window | 
 integer; the window size in time units.  | 
na.rm | 
 logical; should NAs be discarded?  | 
In essence, this function iterates of elements in x, looking
back through previous elements until the corresponding element in
time exceeds the specified window. For example, if the
iteration was at x[100], where time[100] == 60 (seconds), a
cumulative mean would be applied to previous values of x until
time[i] == 30, if window = 30.
A vector of the same length as x.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  | library(dplyr, warn.conflicts = FALSE)
data(chaingang)
# 'chaingang' is sampled uniformly at 1 Hz, but lets
# pretend it's messy...
chaingang <- sample_n(chaingang, 1500) %>% arrange(time.s)
diff(chaingang$time.s) %>% table
# With this function, we can still get a 30 second rolling
# average:
chaingang <- mutate(chaingang,
                    power.30mean = roll_mean.time(power.W, time.s, 30))
plot(power.W ~ time.s, type = "l", col = "gray", data = chaingang)
lines(power.30mean ~ time.s, data = chaingang)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.