我正在写一个R代码来计算我给定数据的每分钟数据点的平均值。
我的数据框是
2017-06-14 10:51:24,199 ERROR [qtp592179046-16] com.retailwave.rwos.compartment.rest.exception.RWCompartmentRestExceptionMapper - Exception caught at Mapper : Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.6.4.v20160829-44060b6): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLTransactionRollbackException: A lock could not be obtained within the time requested
我希望我的结果数据框有
TIME PRICE
2013-01-01 23:54:54 20133
2013-01-01 23:54:50 20133
2013-01-01 23:53:34 20134
2013-01-01 23:53:40 20131
2013-01-01 22:52:54 20131
2013-01-01 22:52:50 20132
我使用代码段将我的数据分成小时和分钟。
TIME PRICE
2013-01-01 23:54:00 20133
2013-01-01 23:53:00 20132.5
2013-01-01 23:52:00 20131.5
使用包trade_1[, c('Hour', 'Minute') := .(data.table::hour("TIME"), minute("TIME"))
+ ][, .(Avg = mean("PRICE")), .(Hour, Minute)]
我收到以下错误
lubridate
有人可以帮帮我吗?
我已使用Error in `:=`(c("Hour", "Minute"), .(data.table::hour("TRADETIME"), minute("TRADETIME"))) :
could not find function ":="
答案 0 :(得分:0)
我们需要转换为data.table
并且不需要变量引用
library(data.table)
setDT(trade_1)[, c('Hour', 'Minute') := .(hour(TIME), minute(TIME))
][, .(Avg = mean(PRICE)), .(Hour, Minute)]
# Hour Minute Avg
#1: 23 54 20133.0
#2: 23 53 20132.5
#3: 22 52 20131.5