data.table中括号前面的圆点

Hac*_*k-R 2 r data.table kaggle

我不熟悉这种df[, .(...), Col]表示法.如果我遗漏了一些明显的东西,我很抱歉,但我找不到这种符号样式的参考,尽管它看起来非常有用.

它似乎正在实施聚合.根据下面代码中这种符号的位置,我希望它来自R而不是来自h2o但我试过检查两者都无济于事.

这个例子来自Kaggle比赛并且代码可以工作(重现它在这里):

trainHex<-as.h2o(train[,.(
  dist   = mean(radardist_km, na.rm = T),
  refArea5   = mean(Ref_5x5_50th, na.rm = T),
  refArea9  = mean(Ref_5x5_90th, na.rm = T),
  meanRefcomp = mean(RefComposite,na.rm=T),
  meanRefcomp5 = mean(RefComposite_5x5_50th,na.rm=T),
  meanRefcomp9 = mean(RefComposite_5x5_90th,na.rm=T),
  zdr   = mean(Zdr, na.rm = T),
  zdr5   = mean(Zdr_5x5_50th, na.rm = T),
  zdr9   = mean(Zdr_5x5_90th, na.rm = T),
  target = log1p(mean(Expected)),
  meanRef = mean(Ref,na.rm=T),
  sumRef = sum(Ref,na.rm=T),
  records = .N,
  naCounts = sum(is.na(Ref))
),Id][records>naCounts,],destination_frame="train.hex")
Run Code Online (Sandbox Code Playgroud)

我希望文档和/或对此的一个很好的解释.

Jos*_*ien 5

.()是一个data.table方便函数,充当简洁别名list().让事情变得复杂一点点(主要是那些像你一样的人,试图弄清楚它到底发生了什么.!)事实上它只是在调用范围内被解释为 [.data.table().

来自?data.table:

 DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
 setkey(DT,x,y)             # 2-column key

 DT["a"]                    # join to 1st column of key
 DT[.("a")]                 # same, .() is an alias for list()
 DT[list("a")]              # same

 ## But note that *this* doesn't work (my addition --- not in ?data.table)
 .("a")
Run Code Online (Sandbox Code Playgroud)