Skip to content
Prev 306154 / 398506 Next

POSIXct coerced into numeric when filling a data frame

Hi,
Upon running your code, the "y" I am getting is:
y
#? ID????? first???? second
#1? a 1320003900 1320004800
#2? b 1320003000 1320003900

This you can convert back by:
within(y,{first<-as.POSIXct(first,origin="1970-01-01");second<-as.POSIXct(second,origin="1970-01-01")})
#? ID?????????????? first????????????? second
#1? a 2011-10-30 20:45:00 2011-10-30 21:00:00
#2? b 2011-10-30 20:30:00 2011-10-30 20:45:00

A.K.




----- Original Message -----
From: Arnaud Duranel <arnaud.duranel.09 at ucl.ac.uk>
To: arun <smartpink111 at yahoo.com>
Cc: R help <r-help at r-project.org>
Sent: Monday, September 24, 2012 10:30 AM
Subject: [R] POSIXct coerced into numeric when filling a data frame

A.K., many thanks for your reply.
I have realised there was a mistake in my code, and that the example 
could have been clearer; my apologies for this, the corrected code is below:
15:45:00 GMT", "2011-10-30 16:00:00 GMT", "2012-06-22 09:30:00 GMT", 
"2012-06-22 10:00:00 GMT"))
15:30:00 GMT", "2011-10-30 15:45:00 GMT", "2012-06-22 10:00:00 GMT"))
[1] "2011-10-30 15:45:00 GMT"
+?  y[i,"ID"]<-names(x[i])
+?  y[i,"first"]<-x[[i]][as.Date(x[[i]])=="2011/10/30"][1]
+?  y[i,"second"]<-x[[i]][as.Date(x[[i]])=="2011/10/30"][2]
+ }
?  ID? ? ? first? ?  second
1? a 1319989500 1319990400
2? b 1319988600 1319989500

where I would need:
? ? ? ? ? ? ? ? ID? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?  first? ? ? ? ? ? ? 
? ? ? ?  second
1? ? ? ? ? ? ? a? ?  2011-10-30 15:45:00? ?  2011-10-30 16:00:00
2? ? ? ? ? ? ? b? ?  2011-10-30 15:30:00? ?  2011-10-30 15:45:00

The POSIXct objects in my list do not have the same length; and I need 
to extract those POSIXct values that match a specific date (2011-10-30 
in this example), while keeping them in POSIXct format.

Many thanks
Arnaud
On 24/09/2012 13:29, arun wrote: