简体   繁体   English

R编程,拆分时间序列日期

[英]R programming , split time series date

I just have a data file with one column of time series: 我只有一个带有一列时间序列的数据文件:

'2012-02-01 17:42:44'                       
'2012-02-01 17:42:44'          
'2012-02-01 17:42:44'

data.frame(table(cut(MyDates, breaks = c("week", "hours")))

After converting the the column to as.POSIXct , i'm trying to create a frequency table by weeks and hours of a day 将列转换为as.POSIXct后,我试图按一天的几周和几小时创建一个频率表
This code does not work. 此代码不起作用。

Please suggest? 请提出建议?

The right argument to use is breaks = "hour" (check ?cut.POSIXt ) 正确使用的参数是breaks = "hour" (检查?cut.POSIXt

MyDates<-read.table(text= "2012-02-01 17:42:44
                            2012-02-01 17:42:44         
                            2012-02-01 17:42:44",
                    header = F, sep = "_", 
                    col.names = "date")

# convet to class POSIXct
MyDates <- as.POSIXct(MyDates$date)

# your frequency tables
hours <- table(cut(MyDates, breaks = "hour"))
weeks <- table(cut(MyDates, breaks = "week"))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM