Skip to content
Prev 245797 / 398506 Next

Lost in POSIX

Dimitri Shvorob wrote:
Well, perhaps you should read the error message or the "Value" section of 
?trunc.POSIXt, and convert the result to a compact type...

 > df$min <- trunc( df$t, units="mins" )
Error in `$<-.data.frame`(`*tmp*`, "min", value = list(sec = 0, min = c(3L,  :
   replacement has 9 rows, data has 3
 > df$min <- as.POSIXct( trunc( df$t, units="mins" ) )
 > str(df)
'data.frame':   3 obs. of  2 variables:
  $ t  : POSIXct, format: "2002-10-06 21:03:26" "2002-10-07 00:02:24" ...
  $ min: POSIXct, format: "2002-10-06 21:03:00" "2002-10-07 00:02:00" ...