Skip to content

Odd behaviour of as.POSIXct

5 messages · Brad Patrick Schneid, Duncan Murdoch, Johannes Egner +1 more

#
day doesn't exist?
That would be the 1st problem.
Johannes Egner wrote:
--
View this message in context: http://r.789695.n4.nabble.com/Odd-behaviour-of-as-POSIXct-tp3670414p3670454.html
Sent from the R help mailing list archive at Nabble.com.
#
On 15/07/2011 12:15 PM, Johannes Egner wrote:
"day" in the loop above is an integer without a class, it's not a Date.  
If you did

for (day in days) {
   class(day) <- class(days)
   print(as.POSIXct(day))
}

you won't get an error.  (I don't know if you'll be happy with what you 
get; the time zone is an issue.)

Duncan Murdoch
#
Do you realise that that's a list with length one?

I suspect you want

days <- as.list( as.Date( c("2000-01-01", "2000-01-02") ) )
for (day in days) {
  print(day)
}

Hadley