我只有一个包含一列时间序列的数据文件:
'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")))
将该列转换为as.POSIXct后,我尝试按星期和小时创建频率表
此代码不起作用。
请建议?
答案 0 :(得分:2)
使用的正确参数是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"))