Skip to content

Problem with as.POSIXct()

2 messages · circe, Stefan Petersson

#
Hi, when I type in these words:
the real output is:
   [1] "2011-06-01 17:21:24.830 CST" "2011-06-01 17:21:24.283 CST"
   
rather than the expected one:
   [1] "2011-06-01 17:21:24.083 CST" "2011-06-01 17:21:24.283 CST"

How can I deal with such milliseconds less than 100?

Thanks



--
View this message in context: http://r.789695.n4.nabble.com/Problem-with-as-POSIXct-tp3565424p3565424.html
Sent from the R help mailing list archive at Nabble.com.
#
circe <tju_circe <at> hotmail.com> writes:
http://r.789695.n4.nabble.com/Problem-with-as-POSIXct-tp3565424p3565424.html
Well, to me the R is behaving as expected. I.e. .83 = .830. If Your dates come
in a format like You describe, You need to manually add a leading zero to Your
milliseconds.

A suggestion to work from:

for(i in 1:length(a)){
  if(nchar(a[i]) == 23){
    print(a[i])
  }else{
    print( paste(substr(a[i],1,20),0,substr(a[i],21,22),sep='') ) 
  }
}