介绍

R 的可扩展数据处理

Simon Urbanek

Member of R-Core, Lead Inventive Scientist, AT&T Labs Research

bigmemory

  • 所有数据必须存于单个磁盘
  • 数据必须表示为矩阵
R 的可扩展数据处理

iotools

  • 数据可为多种类型,如数据框
  • 跨多台机器存储
  • 按"块"处理数据
R 的可扩展数据处理

按顺序逐块处理

  • 通过控制块大小限制资源使用
  • 允许结果在块间传递
R 的可扩展数据处理

各块独立处理

  • 对应于 split-compute-combine
  • 各块之间不可共享信息
  • 可并行与分布式处理
R 的可扩展数据处理

用 Map/Reduce 实现更复杂的操作

# 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
R 的可扩展数据处理

并非所有内容都适合 Split-Apply-Combine

需要一次性获取全部数据的操作,无法用 Split-Apply-Combine 计算。

示例:中位数

R 的可扩展数据处理

但是……

许多回归流程可用 split-apply-combine 表达

R 的可扩展数据处理

开始练习!

R 的可扩展数据处理

Preparing Video For Download...