Learn R Programming

accelerometry (version 2.1)

movingaves: Moving averages

Description

This function returns either a vector of moving averages or the maximum moving average for some input vector x.

Usage

movingaves(x, window, return.max = FALSE, skipchecks = FALSE)

Arguments

x
Input vector.
window
Window length for moving averages.
return.max
If TRUE, function returns the maximum moving average; if FALSE, function returns a vector of moving averages.
skipchecks
If TRUE, function skips error checking code and runs slightly faster.

Value

  • Either a single numeric value indicating the maximum moving average, or a vector of length (length(x)-window+1) with moving averages.

Details

NA

References

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

See Also

blockaves

Examples

Run this code
# Load in sample data frame
data(unidata)

# Get data from ID number 21005
counts.part1 <- unidata[unidata[,"seqn"]==21005,"paxinten"]

# Create vector of all 10-minute moving averages
all.10min.averages <- movingaves(x = counts.part1, window = 10)

# Calculate maximum 10-minute moving average
max.10min.average <- movingaves(x = counts.part1, window = 10, return.max = TRUE)

Run the code above in your browser using DataLab