2014-10-30 65 views
0

我有一个POSIXct对象,我只想将来自该对象的日期与存储在因子对象中的时间组合在一起。这里是代码:结合一个日期和一个因素来创建一个POSIXct日期时间和条到列

originalDate<- as.POSIXct("2014-10-27 13:39:01.885") 

time<- factor("13:30:00.994") 
class(time) 
time 

#I'd like to combine the date from "originalDate" and the time from "time" 
    #so is of the type POSIXct and is --> 2014-10-27 13:30:00.994 

此外,一旦我有新的POSIXct对象,我需要将小时,分钟,秒和毫秒剥离成列。

任何想法?

回答

0

也许

temp <- paste(as.Date(doriginalDate), time) 
temp 
## [1] "2014-10-27 13:30:00.994" 
as.numeric(strsplit(format(as.POSIXct(temp), "%H:%M:%OS3"), ":|\\.")[[1]]) 
## [1] 13 30 0 993 
+0

真棒。你知道如何从输出中提取小时,分钟,秒和毫秒吗? – user3022875 2014-10-30 20:30:19

+0

是的,但你想怎么做?也就是说,你想要的新产品是什么? – 2014-10-30 20:31:57

+0

期望的输出是数字类型的小时= 13分钟= 30秒= 0和毫秒= 994 – user3022875 2014-10-30 20:34:10

相关问题