[R] PosixCT subsecond accuracy

Hasan Diwan hasan.diwan at gmail.com
Fri Jan 27 19:44:43 CET 2012


A sample of the data I have is:
> head(sensor)
      logged_on    accx   accy   accz compassx  compassy compassz
gyrox      gyroy      gyroz
1 1326561428000 -0.4602 0.8346 0.0936 0.145508 -0.350586 0.259766
59.617390  28.521740  59.617390
2 1326561428050 -0.4212 1.0452 0.1326 0.219727 -0.321289 0.241211
88.695656  27.478260  88.695656
3 1326561428100 -0.2496 1.3416 0.2886 0.214844 -0.326172 0.141602
29.565218 -14.747826  29.565218
4 1326561428150 -0.3276 1.0374 0.0546 0.261719 -0.314453 0.243164
8.765218  16.556522   8.765218
5 1326561428200 -0.3588 1.0686 0.2418 0.229492 -0.307617 0.212891
-33.808697  35.756523 -33.808697
6 1326561428250 -0.3120 1.0686 0.2652 0.261719 -0.289062 0.246094
-40.347828  24.626087 -40.347828

The first column is epoch time. I read that POSIXct has support for
this, sort of[1]. So, I tried:
> sensor[,1] <- as.POSIXct(sensor[,1], origin='1970-01-01 12:00:00.000')
> head(sensor)
            logged_on    accx   accy   accz compassx  compassy
compassz      gyrox      gyroy      gyroz
1 1970-01-01 12:00:20 -0.4602 0.8346 0.0936 0.145508 -0.350586
0.259766  59.617390  28.521740  59.617390
2 1970-01-01 12:00:10 -0.4212 1.0452 0.1326 0.219727 -0.321289
0.241211  88.695656  27.478260  88.695656
3 1970-01-01 12:00:00 -0.2496 1.3416 0.2886 0.214844 -0.326172
0.141602  29.565218 -14.747826  29.565218
4 1970-01-01 12:00:50 -0.3276 1.0374 0.0546 0.261719 -0.314453
0.243164   8.765218  16.556522   8.765218
5 1970-01-01 12:00:40 -0.3588 1.0686 0.2418 0.229492 -0.307617
0.212891 -33.808697  35.756523 -33.808697
6 1970-01-01 12:00:30 -0.3120 1.0686 0.2652 0.261719 -0.289062
0.246094 -40.347828  24.626087 -40.347828

That reading is quite far off, a more accurate reading should be:
> sensor[,1] <- as.POSIXct(sensor[,1]/1000, origin='1970-01-01 12:00:00')
> head(sensor)
            logged_on    accx   accy   accz compassx  compassy
compassz      gyrox      gyroy      gyroz
1 2012-01-15 05:17:08 -0.4602 0.8346 0.0936 0.145508 -0.350586
0.259766  59.617390  28.521740  59.617390
2 2012-01-15 05:17:08 -0.4212 1.0452 0.1326 0.219727 -0.321289
0.241211  88.695656  27.478260  88.695656
3 2012-01-15 05:17:08 -0.2496 1.3416 0.2886 0.214844 -0.326172
0.141602  29.565218 -14.747826  29.565218
4 2012-01-15 05:17:08 -0.3276 1.0374 0.0546 0.261719 -0.314453
0.243164   8.765218  16.556522   8.765218
5 2012-01-15 05:17:08 -0.3588 1.0686 0.2418 0.229492 -0.307617
0.212891 -33.808697  35.756523 -33.808697
6 2012-01-15 05:17:08 -0.3120 1.0686 0.2652 0.261719 -0.289062
0.246094 -40.347828  24.626087 -40.347828

But now the fractional seconds are missing... Help? -- H
-- 
Sent from my mobile device
Envoyait de mon portable

1. https://stat.ethz.ch/pipermail/r-devel/2009-March/052621.html



More information about the R-help mailing list