0

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.

Lucy
  • 3
  • 1
  • Can you provide sample data? Otherwise it is hard to help you http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – CAFEBABE Jan 08 '16 at 11:41

2 Answers2

2

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)
scoa
  • 19,359
  • 5
  • 65
  • 80
  • This code does exactly what I wanted. I am just wondering when I am asked to use 10min averaged data. Do they want me to use the procedure you described or do they in fact mean the moving average? – Lucy Jan 08 '16 at 13:11
  • I cannot answer this, you will have to ask whoever has been asking you to do this – scoa Jan 08 '16 at 13:14
0

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.

CAFEBABE
  • 3,983
  • 1
  • 19
  • 38