次のようなdata.tableがあります。
tbl
lon lat hour ens date value
1: 254 31 12 0 1994010100 0
2: 254 31 12 0 1994010200 0
3: 254 31 12 0 1994010300 0
4: 254 31 12 0 1994010400 0
5: 254 31 12 0 1994010500 0
---
40494956: 269 39 24 10 2007122700 200
40494957: 269 39 24 10 2007122800 130
40494958: 269 39 24 10 2007122900 240
40494959: 269 39 24 10 2007123000 230
40494960: 269 39 24 10 2007123100 150
そして次のような別のもの:
locs
lon lat
1: 260 33
2: 261 33
3: 262 33
4: 263 33
5: 260 34
6: 261 34
そして、私は現在、必要な形にするために dcast でこれを行っています:
temp <- dcast(tbl[locs], date ~ lon + lat + hour, fun.aggregate=mean, value.var="value")
これはまさに私が望んでいることです(列名も!)が、非常に遅いです。私はそれを行うdata.tableの方法が欲しいのですが、ここでいくつかのスレッドを読んだ後でも、まだうまくいきません。私の最新の試みはこれです:
temp <- tbl[locs, list(mean = mean(value), sd = sd(value)), by = list(date, lon, lat, hour)]
変数を折りたたむens
(これは正常に機能し、sdも計算していることに注意してください)が、形状を変更することはできません。私の再形成の試みは次のとおりです。
temp[, as.list(setattr(list(mean,sd), 'names', list(lon, lat, hour))), by=list(date)]
Error in setattr(list(mean, sd), "names", list(lon, lat, hour)) :
'names' attribute [3] must be the same length as the vector [2]
もちろん、どんな助けも大歓迎です。ありがとうございました。