【发布时间】:2017-07-23 07:29:10
【问题描述】:
嗨,我有一个奇怪的 R 行为:
我有一个包含日期、时间和一些值的数据集:
Date Time Global_active_power
2006-12-16 17:24:00 4.216
2006-12-16 17:25:00 5.360
2006-12-16 18:24:00 6.216
2006-12-16 18:25:00 5.390
2006-12-17 07:24:00 3.216
2006-12-17 17:25:00 1.360
2006-12-17 17:24:00 2.216
2006-12-17 18:25:00 6.360
从前 2 列中,我想构建一个组合列,其中包含 1 列中的日期 + 时间 - 类似这样:
Date Time Global_active_power combinedTime
2006-12-16 17:24:00 4.216 2006-12-16 17:24:00
现在的问题是,这样做时我总是把今天的日期混进去:
Date Time Global_active_power combinedTime
2006-12-16 17:24:00 4.216 2006-12-16 2017-07-23 17:24:00
这是我的代码:
Data$Date<- as.Date(Data$Date, "%d/%m/%Y")
Data$Time<-strptime(Data$Time, "%H:%M:%S")
Data1 <-subset(Data, (Date < "2007-02-03" ) )
Data2 <-subset(Data1,(Date > "2007-01-31" ) )
t <- paste((Data2$Date), (Data2$Time))
Data2<-cbind(Data2,t)
在我的时间列中,我只有时间。我想我的问题来了当我在我的代码中运行这一行时:
Data$Time<-strptime(Data$Time, "%H:%M:%S")
我突然得到今天的日期加上我的专栏的时间。为什么 ?我只想要时间
感谢您的帮助
【问题讨论】:
-
请参阅我的answer 来回答您的问题。