gpt4 book ai didi

r - data.table 中圆括号前的点,.()

转载 作者:行者123 更新时间:2023-12-02 09:30:23 26 4
gpt4 key购买 nike

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

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

该示例来自 Kaggle 比赛并且代码有效(重现它 go here):

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")

我会喜欢文档和/或对此的一个很好的解释。

最佳答案

.()数据表便利函数,作为 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")
另见小插图 Introduction to data.table :

data.table also allows wrapping columns with .() instead of list(). It is an alias to list(); they both mean the same. Feel free to use whichever you prefer

关于r - data.table 中圆括号前的点,.(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33808705/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com