View source: R/lumpmean_function.R
lumpmean | R Documentation |
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.
lumpmean(x, y, tspan)
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. |
A numeric vector of the running mean. NAs provided on tail when the span is not met.
### 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.