自訂模糊比對

R 中級 Regular Expressions

Angelo Zehr

Data Journalist

結合兩種模糊比對

電影資料表

R 中級 Regular Expressions

結合兩種模糊比對

欄位標示

R 中級 Regular Expressions

模糊比對:輔助函式

針對字串比對:

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

針對數值比對:

close_to_each_other <- function(left, right) {
  abs(left - right) <= 3
}
R 中級 Regular Expressions

模糊連接(join)

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 中級 Regular Expressions

模糊連接:結果

連接後的資料表

R 中級 Regular Expressions

一起來練習吧!

R 中級 Regular Expressions

Preparing Video For Download...