Can someone please fix this snippet? (i.e. append to the dataframe a column containing "truncated" time value)?
df = structure(list(t = structure(c(1033963406.044, 1033974144.847, 1033988418.836), class = c("POSIXt", "POSIXct"))), .Names = "t", row.names = c(NA, 3L), class = "data.frame") # Try 1 df$day = trunc.POSIXt(as.POSIXlt(df$t, origin = "1970-01-01"), units = "day") Error in `$<-.data.frame`(`*tmp*`, "day", value = list(0, 0L, 0L, 7L, : replacement has 9 rows, data has 3 # Try 2 f = function(t) trunc.POSIXt(as.POSIXlt(t, origin = "1970-01-01"), units = "day") df$day = sapply(df$t, f) Error in `$<-.data.frame`(`*tmp*`, "day", value = list(sec = 0, min = 0L, : replacement has 9 rows, data has 3 -- View this message in context: http://r.789695.n4.nabble.com/Lost-in-POSIX-tp3052768p3052768.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.