我正在尋找一種方式來使用分割申請,結合有R的data.table
包策略。「* R中的數據表層」功能
library(data.table)
# take a data.table object, return integer
func <- function(DT)
{
DT$a * DT$a
}
DT = data.table(
a = 1:50
# ... further fields here
b = rep(1:10, 5)
)
# this obviously won't work:
DT[, result:=func, by=b]
# but this will (based on @Aruns answer below)
DT[, result:=func(.SD), by=b]
雖然這在這裏很簡單data.table
,更復雜結構,我想能夠提取到的邏輯功能和發送的子集作爲data.table
s到他們,而不必爭取所有字段名
@阿倫,我已經編輯了一下這個問題,但我沒有意識到'.SD'會在一瞬間。 – nikola 2013-02-23 21:43:12