[R] Help with finding mean at 1 second interval

arun smartpink111 at yahoo.com
Wed Mar 19 17:27:51 CET 2014


Hi Satish,

Pascal's suggestion is better. 

Please use ?dput() to show the example data.

 op <- options(digits.secs=6)
library(zoo)
##added a couple more rows
 dat <- read.zoo(text="V1 V2 V3 V4 V5 V6
'2014-03-14 22:41:46.988804'  10   2   8   3  14
'2014-03-14 22:41:46.991126'  13   4   9   5  15
'2014-03-14 22:41:46.993506'  12   4   8   3  14
'2014-03-14 22:41:46.993755'  19   4  15   5  22
'2014-03-14 22:41:46.997780'  21   5  16   7  24
'2014-03-14 22:41:47.000154'  18   5  13   3  21
'2014-03-14 22:41:47.002376'  21   5  16   6  23
'2014-03-14 22:41:47.011106'  12   4   8   3  14
'2014-03-14 22:41:47.012691'  12   4   8   3  16
'2014-03-14 22:41:47.017579'  11   2   9   3  12
'2014-03-14 22:41:47.019463'  12   5   7   3  15
'2014-03-14 22:41:47.020247'  14   6   8   3  17
'2014-03-15 22:41:47.017579'  11   2   9   3  12
'2014-03-15 22:41:47.019463'  12   5   7   3  15
'2014-03-15 22:41:47.020247'  14   6   8   3  17", index.column=1,sep="",header=TRUE, format= "%Y-%m-%d %H:%M:%OS",FUN=as.POSIXct) 
options(op)
library(xts)
 period.apply(dat,endpoints(dat,"seconds"),mean)
#                          V2       V3        V4       V5       V6
#2014-03-14 22:41:46 15.00000 3.800000 11.200000 4.600000 17.80000
#2014-03-14 22:41:47 14.28571 4.428571  9.857143 3.428571 16.85714
#2014-03-15 22:41:47 12.33333 4.333333  8.000000 3.000000 14.66667


A.K.





On Tuesday, March 18, 2014 7:27 PM, Pascal Oettli <kridox at ymail.com> wrote:
Hello,

Please have a look at the "xts" package.

Please don't post in HTML.

Regards,
Pascal

On Wed, Mar 19, 2014 at 12:26 AM, Satish Anupindi Rao
<satish.anupindi.rao at ericsson.com> wrote:
> Hi,
> I have a zoo object with the first column as index. The columns have not been named yet... but that I can change. It looks like this :
>                                                           V2 V3 V4 V5 V6
> 2014-03-14 22:41:46.988804  10   2   8   3  14
> 2014-03-14 22:41:46.991126  13   4   9   5  15
> 2014-03-14 22:41:46.993506  12   4   8   3  14
> 2014-03-14 22:41:46.993755  19   4  15   5  22
> 2014-03-14 22:41:46.997780  21   5  16   7  24
> 2014-03-14 22:41:47.000154  18   5  13   3  21
> 2014-03-14 22:41:47.002376  21   5  16   6  23
> 2014-03-14 22:41:47.011106  12   4   8   3  14
> 2014-03-14 22:41:47.012691  12   4   8   3  16
> 2014-03-14 22:41:47.017579  11   2   9   3  12
> 2014-03-14 22:41:47.019463  12   5   7   3  15
> 2014-03-14 22:41:47.020247  14   6   8   3  17
>
> I would like to find the mean of the V2 to V6 columns on a per second interval. Would anyone please be able to help me with a function and implementation for that please?
>
> Thanks so much!
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan


______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list