根据日期时间,即7月1日至2013年7月7日0:00,2013年1月7日1:00,我有七个季度的数据。我应该有最大可能的92 * 24 = 2208观察。出于某种原因,我在一些数据框中有超过2208个观测值。
这是我的数据框的输入
dput(head)
structure(list(DATEHOUR = c("07-01-13 0:00", "07-01-13 10:00",
"07-01-13 11:00", "07-01-13 12:00", "07-01-13 13:00", "07-01-13 14:00"
), ImpressionsA.x = c(156, 564, 884, 1365, 1864, 1470), ImpressionsM.x = c(83,
274, 338, 664, 807, 757), ImpressionsA.y = c(0.4, 0, 0.4, 0,
0, 0), ImpressionsM.y = c(0.2, 0, 0.3, 0, 0, 0), Branded = c(0,
0, 0, 0, 0, 0), ESI = c(0, 0, 0, 0, 0, 0), ImpressionsA.T = c(156.4,
564, 884.4, 1365, 1864, 1470), ImpressionsM.T = c(83.2, 274,
338.3, 664, 807, 757), Leads.T = c(0, 0, 0, 0, 0, 0)), .Names = c("DATEHOUR",
"ImpressionsA.x", "ImpressionsM.x", "ImpressionsA.y", "ImpressionsM.y",
"Branded", "ESI", "ImpressionsA.T", "ImpressionsM.T", "Leads.T"
), row.names = c(1L, 3L, 4L, 5L, 6L, 7L), class = "data.frame")
我阅读了以下帖子和链接http://astrostatistics.psu.edu/su07/R/html/base/html/strptime.html,format a Date column in a Data Frame,Convert data frame with date column to timeseries并试图执行此操作:test$timestamp<-as.Date(as.character(test$DATEHOUR), format="%m%d%Y%I%M")
和组合,但它没有成功。我的目标是通过时间序列得到2208(或任何不重复的观察)。我是R的新手和编码,所以请原谅我的新手语法理解。
答案 0 :(得分:2)
试试这个:
> as.POSIXct(dd$DATEHOUR, format="%m-%d-%y %H:%M")
[1] "2013-07-01 00:00:00 PDT" "2013-07-01 10:00:00 PDT" "2013-07-01 11:00:00 PDT" "2013-07-01 12:00:00 PDT"
[5] "2013-07-01 13:00:00 PDT" "2013-07-01 14:00:00 PDT"
答案 1 :(得分:2)
如果您懒得手动编写格式,可以尝试lubridate
package
library(lubridate)
mdy_hm(df$DATEHOUR)
## [1] "2013-01-07 00:00:00 UTC" "2013-01-07 10:00:00 UTC" "2013-01-07 11:00:00 UTC"
## [4] "2013-01-07 12:00:00 UTC" "2013-01-07 13:00:00 UTC" "2013-01-07 14:00:00 UTC"