circe <tju_circe <at> hotmail.com> writes: > > Hi, when I type in these words: > > > a=c("2011-06-01 17:21:24.83", "2011-06-01 17:21:24.283") > > as.POSIXct(a) > > 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. > >
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='') ) } } ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.