そのデータを含む example.csv という名前のファイルがあります。
day,number,price,pr
2010-01-01 00:01:00,1,0.4,2
2010-01-01 00:02:00,1,1.2,4
2010-01-01 00:03:00,1,2.5,6
2010-01-01 00:04:00,1,9.1,2
2010-01-01 00:05:00,2,3.4,7
2010-01-01 00:06:00,2,6.9,9
2010-01-01 00:07:00,2,8.9,2
2010-01-01 00:08:00,3,9.1,5
2010-01-01 00:09:00,3,4.2,9
2010-01-01 00:10:00,3,11.2,2
2010-01-01 00:11:00,4,53.12,4
2010-01-01 00:12:00,4,45.21,1
2010-01-01 00:12:00,4,1.1,5
2010-01-01 00:13:00,4,3.43,2
2010-01-01 00:14:00,4,21.42,4
データのロード:
example = read.csv(file="path/example.csv", header=TRUE, sep=",")
日に基づく
ddx <- xts(x = example[, c("number", "price", "pr" )], order.by = as.POSIXct(example[, "day"], tz = "GMT", format = "%Y-%m-%d %H:%M:%S"))
これを適用すると、列の日付と価格が出力されます。
period.apply(ddx$number, endpoints(ddx, on = "minutes", k = 3), sum)