mydata
10:17:37
09:48:11
10:20:25
10:52:12
10:52:08
10:47:42
09:57:13
如何将这些值转换为时间格式(仅限时间)?
你能否提供日期和时间的代码?
答案 0 :(得分:2)
我们可以使用times
chron
library(chron)
library(dplyr)
mydata %>%
mutate(v1 = times(v1))
或hms
lubridate
library(lubridate)
mydata %>%
mutate(v1 = hms(v1))
如果我们需要当前日期和'时间'
mydata %>%
mutate(v1 = as.POSIXct(v1, format = "%H:%M:%S"))
mydata <- structure(list(v1 = c("10:17:37", "09:48:11", "10:20:25", "10:52:12",
"10:52:08", "10:47:42", "09:57:13")), .Names = "v1", class = "data.frame", row.names = c(NA,
-7L))