lumpmean: Running mean using a time span instead of the number of...

View source: R/lumpmean_function.R

lumpmeanR Documentation

Running mean using a time span instead of the number of observations.

Description

This function performs a running mean, but instead of averaging based on the number of samples/observations, it take the mean based on a specified time span.

Usage

lumpmean(x, y, tspan)

Arguments

x

A numeric vector to use as a time indicator.

y

A numeric vector of the data to average.

tspan

A numeric value to use as the time span.

Value

A numeric vector of the running mean. NAs provided on tail when the span is not met.

Examples

### Create Test data
testx <- 1
while(testx[length(testx)]<30){
  hold <- testx[length(testx)]+sample(seq(0.1,1,by=0.1),1)
  testx <- c(testx,hold)
  rm(hold)
}
testdf <- data.frame(time=testx,val=sample(1:100,length(testx),replace=TRUE))

### Get the running mean of val for every 5 units of time:
testdf$avg <- lumpmean(x=testdf$time,y=testdf$val,tspan = 5)


Louismp1223/LMP3 documentation built on June 29, 2022, 5:11 p.m.