R 的可扩展数据处理
Simon Urbanek
Member of R-Core, Lead Inventive Scientist, AT&T Labs Research
# Create a random vector
x <- rnorm(100)
# Find the mean
mean(x)
-0.01996644
# Take the sum of chunks of
# the vector
sl <- Map(function(v) {
c(sum(v), length(v))},
list(x[1:25], x[26:100]))
# Add the sums and lengths
slr <- Reduce(`+`, sl)
# Find the mean
slr[1]/slr[2]
-0.01996644
需要一次性获取全部数据的操作,无法用 Split-Apply-Combine 计算。
示例:中位数
许多回归流程可用 split-apply-combine 表达
R 的可扩展数据处理