我有很多测量值,每分钟记录一次。某些值具有给定分钟的平均值、最小值和最大值。我想总结/聚合整个 data.frame 每 30 分钟有一个条目,所以
str(wgData)
'data.frame': 115200 obs. of 7 variables:
$ TIMESTAMP : POSIXct, format: "2012-11-24 00:00:00" "2012-11-24 00:01:00" "2012-11-24 00:02:00" 7"2012-11-24 00:03:00" ...
$ RECORD : int 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 ...
$ TPanel : num -0.075 -0.075 -0.075 -0.095 -0.095 -0.095 -0.095 -0.118 -0.118 -0.118 ...
$ VBattery : num 13.8 13.8 13.8 13.8 13.8 ...
$ VBatteryHeating_Avg: num 12.2 12.2 12.2 12.2 12.2 ...
$ VBatteryHeating_Min: num 12.2 12.2 12.2 12.2 12.2 ...
$ VBatteryHeating_Max: num 12.2 12.2 12.2 12.2 12.2 ...
所以我想每 30 分钟计算一次:TIMESTAMP
,TPanel
(面板温度)的平均值,平均值VBattery
,平均值VBatteryHeating_Avg
,最小值VBatteryHeating_Min
,最大值VBatteryHeating_Max
我做了一些成功
wgData30min <- aggregate(list(TP = wgData$TPanel, VB=wgData$VBatteryHeating_Avg, VB_MIN=wgData$VBatteryHeating_Min, VB_MAX=wgData$VBatteryHeating_Min),
list(Timestamp = cut(wgData$TIMESTAMP, "30 min")),
mean)
head(wgData30min)
Timestamp TP VB VB_MIN VB_MAX
1 2012-11-24 00:00:00 -0.1621667 12.15467 12.15333 12.15333
2 2012-11-24 00:30:00 -0.4751667 12.13333 12.13133 12.13133
3 2012-11-24 01:00:00 -0.5647333 12.11167 12.11067 12.11067
4 2012-11-24 01:30:00 -0.4573667 12.09133 12.08967 12.08967
5 2012-11-24 02:00:00 -0.4923667 12.07100 12.07000 12.07000
6 2012-11-24 02:30:00 -0.6469000 12.04933 12.04733 12.04733
...但没有设法传递一组函数以应用于列。任何帮助表示赞赏。