Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将R中的数据帧转换为时间序列-日期小时格式_R_Datetime_Dataframe_Time Series_Posixct - Fatal编程技术网

将R中的数据帧转换为时间序列-日期小时格式

将R中的数据帧转换为时间序列-日期小时格式,r,datetime,dataframe,time-series,posixct,R,Datetime,Dataframe,Time Series,Posixct,我有从7月到9月的三个季度的数据,按日期小时计算,即2013年1月7日0:00、2013年1月7日1:00。我应该有最大可能的92*24=2208个观察值。出于某种原因,我在一些数据框中观察到了2208个以上的结果 这是我的数据帧的dput 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",

我有从7月到9月的三个季度的数据,按日期小时计算,即2013年1月7日0:00、2013年1月7日1:00。我应该有最大可能的92*24=2208个观察值。出于某种原因,我在一些数据框中观察到了2208个以上的结果

这是我的数据帧的dput

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")
我阅读了以下文章和链接,并尝试这样做:
test$timestamp尝试这样做:

> 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"

如果您懒得手动编写格式,可以尝试
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"

所以您阅读了
?strtime
,但决定将
用作.Date
@JoshuaUlrich正如我所说,我以前从未在R上使用过时间序列数据,我对R处理日期时间的多种方式感到困惑。此练习帮助我了解了
?POSIXct
?Lubridate
?strTime
。由于我的数据的特殊性质,特别是最初在EXCEL中制作的CSV文件的日期格式,我将编辑我的问题,并对我面临的问题进行更详细的说明!嗯,我遇到了一个奇怪的问题。我运行以下命令:
require(lubridate)df$datehour2请参见编辑,我认为天是第一个,而实际上月份是第一个。