roll_mean.time: Roll over time windows.

Description Usage Arguments Details Value Examples

Description

A less efficient implementation of roll_mean that can roll over inconsistently sampled data by a specified time window.

Usage

1

Arguments

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?

Details

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.

Value

A vector of the same length as x.

Examples

 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)

jmackie4/elpatron documentation built on May 19, 2019, 12:49 p.m.