如果您不将数据分解为子集,那么您可以使用该data.table
库 -
library(data.table)
RawData <- data.table(
Season = c("s1997","s1997","s1997","s1997","f1997","f1997","f1997","f1997"),
TMAX = rnorm(40,8),
TMIN = rnorm(10,8)
)
MeanData <- RawData[,
list(
TMAXmean = mean(TMAX),
TMINmean = mean(TMIN)
),
by = "Season"
]
RawData
看起来像这样-
> RawData
Season TMAX TMIN
1: s1997 40.87113 10.474463
2: s1997 40.16536 9.437184
3: s1997 41.39432 9.562281
4: s1997 40.08575 10.357866
5: f1997 39.14282 8.880483
6: f1997 39.47253 10.674257
7: f1997 38.30043 10.493501
8: f1997 38.16162 10.758552
像这样的输出 -
> MeanData
Season TMAXmean TMINmean
1: s1997 40.62914 9.957948
2: f1997 38.76935 10.201699