自定义模糊匹配

R 中级正则表达式

Angelo Zehr

Data Journalist

合并两个模糊匹配

电影表

R 中级正则表达式

合并两个模糊匹配

高亮列

R 中级正则表达式

模糊匹配:辅助函数

对于字符串比较:

small_str_distance <- function(left, right) {
  stringdist(left, right) <= 5
}

对于数值比较:

close_to_each_other <- function(left, right) {
  abs(left - right) <= 3
}
R 中级正则表达式

模糊连接

fuzzy_left_join(
  a, b,
  by = c(
    "title" = "prod_title",
    "year" = "prod_year"
  ),
  match_fun = c(
    "title" = small_str_distance,
    "year" = close_to_each_other
  )
)
R 中级正则表达式

模糊连接:结果

连接后的表

R 中级正则表达式

Let's practice!

R 中级正则表达式

Preparing Video For Download...