r - 计算每秒的事务数

时间:2011-05-18 07:55:42

标签: r

如果我的数据集的日期是这样的:

head(ds$TransStartTmdte) 

[1] "2011-05-09 08:50:12" "2011-05-09 09:03:46" "2011-05-09 09:06:49" "2011-05-09 09:13:05" "2011-05-09 14:21:58" "2011-05-09 14:23:00"

如果每行重新表示“事务”,我该如何计算每秒的事务数。

日期格式为POSIXt

dput(head(ds$TransStartTmdte))

structure(list(sec = c(0.007, 0.013, 0.018, 0.012, 0.043, 0.039
), min = c(34L, 34L, 34L, 34L, 34L, 34L), hour = c(14L, 14L, 
14L, 14L, 14L, 14L), mday = c(9L, 9L, 9L, 9L, 9L, 9L), mon = c(4L, 
4L, 4L, 4L, 4L, 4L), year = c(111L, 111L, 111L, 111L, 111L, 111L
), wday = c(1L, 1L, 1L, 1L, 1L, 1L), yday = c(128L, 128L, 128L, 
128L, 128L, 128L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec", 
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt"))

1 个答案:

答案 0 :(得分:5)

这适合你吗?

table(cut(transactionTime, "secs"))

示例:

plot(table(cut(ds$TransStartTmdte, "secs")), main=mydataset ,xlab="date ", ylab="Trans",pch=20)

enter image description here