将字符时间格式转换为R中的excel时间格式

问题描述 投票:0回答:1

我有以下数据框

times <- c("00:12:23","00:45:01", "02:13:43") moretimes <- c("00:12:23","00:44:23", "05:12:34") x <- as.data.frame(times,moretimes)

我想将所有具有字符时间格式的列转换为与excel兼容的时间格式,因此我可以在excel中求和,我一直在尝试给我们as.Date,但遇到错误。

r excel dplyr lubridate
1个回答
0
投票

我们可以使用as.ITime中的data.table

library(data.table)
times1 <- as.ITime(times)
str(times1)
#'ITime' int [1:3] 00:12:23 00:45:01 02:13:43

有关更新的OP的帖子

x <- data.frame(times,moretimes)
x[] <- lapply(x, as.ITime)
str(x)
#'data.frame':  3 obs. of  2 variables:
# $ times    : 'ITime' int  00:12:23 00:45:01 02:13:43
# $ moretimes: 'ITime' int  00:12:23 00:44:23 05:12:34
© www.soinside.com 2019 - 2024. All rights reserved.