Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
目前我正在尝试将字符串转换为时间格式。例如,我的字符串如下所示:time <- '12:00'。我已经尝试使用 chron-Package。我的代码如下所示:
time <- '12:00'
time <- paste(time,':00', sep = '') time <- times(time)
而不是得到像“12:00:00”这样的值,函数times()总是将对象时间转换为“0.5”我使用了错误的方法吗?
问候
您的代码有效。如果您检查'class()',它是“次”。但是,如果您想要其他方式,请尝试:
time <- '12:00:00' newtime<-as.POSIXlt(time, format = "%H:%M:%S") # The whole date with time t <- strftime(newtime, format="%H:%M:%S") # To extract the time part t #[1] "12:00:00"
干杯!