Lucy
Lucy

Reputation: 3

time averaged data in R

I am given a dataset of 10 hour length (36.000 time points, 1 second=1 time point). For my further analysis I am supposed to use 10min averaged data which would equal 600 time points. So do I understand this right that I have to take the average of the first 600 time points and thats my new time point and then of the next 600 and so on? Which means I end up with a time series of length 60.

How do I do that with R? I thought

xF<-filter(x, 600, sides = 2)

would be the required function but it just changes the values on the y axis.

Upvotes: 0

Views: 124

Answers (2)

scoa
scoa

Reputation: 19867

If your dataset is ordered, you could just create a grouping variable and use tapply:

# simulate data
x <- rnorm(36000)
# create a group variable
group <- factor(rep(1:(36000/600),each=600))
# compute mean for each slice of 600 data point
mean_by_10min <- tapply(x,group,mean)

Upvotes: 2

CAFEBABE
CAFEBABE

Reputation: 4101

It is hard to help you without having your data However, the command looks most likely like

aggregate(iris$Petal.Length,by=list(iris$Petal.Width%/%0.5),mean)

where you need to replace iris$Petal.Length by your values, iris$Petal.Width by the timestamps and 0.5 by 600

Filtering doesn't aggregate your data as I understand your question, hence, you would end up with as many time points.

Upvotes: 0

Related Questions