[R] How to bin/average time points?

2010-11-25 Thread DonDolowy
Dear all, I am pretty new to R only having an introduction course, so please bare with me. I am doing my PhD at The Max Planck Institute of Immunobiology where I am analyzing some calorimetry data from some mice. I have a spreadsheet consisting of measurements of the respiratory exchange rate

Re: [R] How to bin/average time points?

2010-11-25 Thread sachinthaka . abeywardana
It would be something like this (might have to change the syntax a bit) bin_ave=0; while (i lenth(time)){ bin_ave[k]=mean(time(i:i+6)); k=k+1; i=i+6; } if your data is in a table format replace time with mytable$time. hope this helps, Sachin p.s. sorry about corporate

Re: [R] How to bin/average time points?

2010-11-25 Thread jim holtman
try this: # create times 9 minutes apart time - seq(as.POSIXct('2010-11-25 00:00'), by = '9 min', length = 480) mySamp - data.frame(time = time, value = sample(1:100, length(time), TRUE)) # add column to split by hour mySamp$hour - format(mySamp$time, '%Y-%m-%d %H:30') # compute the mean

Re: [R] How to bin/average time points?

2010-11-25 Thread Niels Richard Hansen
Hi Kevin Here is one way: yourData - c(0.730, 0.732, 0.743, 0.757,0.781, 0.731, 0.830, 0.832, 0.843, 0.857, 0.881, 0.831) nrGroups - 2 lengthGroups - 6 tapply(yourData, factor(rep(c(1,nrGroups), each = lengthGroups)), mean) and you will have to adjust the number of groups and if necessary