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
Never mind... options(digits.sec) is what I needed to set... -- H On 27 January 2012 10:44, Hasan Diwan <hasan.diwan at gmail.com> wrote:> 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-- Sent from my mobile device Envoyait de mon portable
> From: Hasan Diwan <hasan.diwan@gmail.com> > To: R Project Help <r-help@r-project.org> > Date: 01/27/2012 10:47 AM > Subject: [R] PosixCT subsecond accuracy > Sent by: r-help-bounces@r-project.org > > 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]/1000, origin='1970-01-0112: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?options, look for digits.secs, and probably set it to 3, but careful of the character representation of those stamps. See David's helpful work around of 24 January at http://r.789695.n4.nabble.com/POSIXct-value-display-incorrect-for-some-values-td4311446.html -- Curt Seeliger, Data Ranger Raytheon Information Services - Contractor to ORD seeliger.curt@epa.gov 541/754-4638 [[alternative HTML version deleted]]