我需要从具有2012-09-27 07:05:59time
形式的列的 data.frame 中分离时间和日期。然后我必须使用和列来提取特定日期/时间的数据。我该怎么做呢?可能是我想做这个的相反。date
time
我尝试使用strptime
函数和lubridate
包,但无法让它工作。
data1 <- structure(list(event.date = structure(list(sec = c(59, 29, 59,
0, 29, 59, 29, 29, 59, 59), min = c(5L, 7L, 15L, 17L, 17L, 19L,
21L, 22L, 22L, 23L), hour = c(7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L,
7L, 7L), mday = c(27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L,
27L), mon = c(8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L), year = c(112L,
112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L, 112L), wday = c(4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), yday = c(270L, 270L, 270L,
270L, 270L, 270L, 270L, 270L, 270L, 270L), isdst = c(0L, 0L,
0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L)), .Names = c("sec", "min", "hour",
"mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt",
"POSIXt"), tzone = c("CST", "GMT", " ")), VE = c(45L, 55L,
45L, 50L, 55L, 35L, 30L, 45L, 55L, 30L)), .Names = c("event.date",
"VE"), row.names = c(NA, 10L), class = "data.frame")
以下给了我NA
:
as.Date(as.character(data1$event.date),"%HH:%MM:%SS")
我也无法lubridate
成功使用...
ymd_hms(as.character(data1$event.date))
我对应该使用哪种日期格式/包感到困惑。