05:00:00 - 28:59:59 time format

独自空忆成欢 提交于 2019-12-05 01:28:08

E.g. add the time as seconds to the date:

df <- read.table(header=T, text="      Date Time.start   
01.01.2013   22:13:07
01.01.2013   22:52:23
01.01.2013   23:34:06
01.01.2013   23:44:25
01.01.2013   27:18:48
01.01.2013   28:41:04", stringsAsFactors=FALSE)

as.POSIXct(df$Date, format="%d.%m.%Y") +
  sapply(strsplit(df$Time.start, ":"), function(t) {
    t <- as.integer(t)
    t[3] + t[2] * 60 + t[1] * 60 * 60
  })

# [1] "2013-01-01 22:13:07 CET" "2013-01-01 22:52:23 CET" "2013-01-01 23:34:06 CET"
# [4] "2013-01-01 23:44:25 CET" "2013-01-02 03:18:48 CET" "2013-01-02 04:41:04 CET"

Just a modification of lukeAs solution:

with(df, as.POSIXct(Date, format="%d.%m.%Y")+
 colSums(t(read.table(text=Time.start, sep=":",header=F))*c(3600,60,1)))
[1] "2013-01-01 22:13:07 EST" "2013-01-01 22:52:23 EST" 
[3] "2013-01-01 23:34:06 EST" "2013-01-01 23:44:25 EST"
[5] "2013-01-02 03:18:48 EST" "2013-01-02 04:41:04 EST"

Using lubridate:

with(dates, mdy(Date) + hms(Time.start))

Generates:

[1] "2013-01-01 22:13:07 UTC" "2013-01-01 22:52:23 UTC"
[3] "2013-01-01 23:34:06 UTC" "2013-01-01 23:44:25 UTC"
[5] "2013-01-02 03:18:48 UTC" "2013-01-02 04:41:04 UTC"
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!