Learn R Programming

accelerometry (version 3.1.2)

blockaves: Block Averages

Description

Calculates block averages (i.e. moving averages but for non-overlapping intervals) or maximum block average. For optimal speed, use integer = TRUE if x is an integer vector and integer = FALSE otherwise. If length(x) is not an exact multiple of window, the last partial segment is dropped.

Usage

blockaves(x, window, integer = FALSE, max = FALSE)

Arguments

x

Integer or numeric vector.

window

Integer value specifying window length.

integer

Logical value for whether x is an integer vector.

max

Logical value for whether to return maximum moving average (as opposed to vector of moving averages).

Value

Numeric value or vector depending on max.

Examples

Run this code
# NOT RUN {
# Load accelerometer data for first 5 participants in NHANES 2003-2004
data(unidata)

# Get data from ID number 21005, Saturday only
counts.sat <- unidata[unidata[, "seqn"] == 21005 & unidata[, "paxday"] == 7, 
                      "paxinten"]
                      
# Calculate and plot hourly count averages
hourly.averages <- blockaves(x = counts.sat, window = 60, integer = TRUE)
plot(hourly.averages)


# }

Run the code above in your browser using DataLab