基于两个条件查找匹配项
在本练习中,您将对包含电影标题的 2 个数据集进行匹配,但它们也包含拼写错误。第一张表 movie_titles 中有 10 部电影,您需要把它们与第二张表 movie_db 匹配。由于这些数据来自扫描文档,包含光学字符识别(OCR)造成的错误。
两张表都包含 title 和 year 两列。请使用这两列来寻找匹配。
创建 2 个辅助函数,用于匹配相似或相同的条目。一个用于电影标题(基于 stringdist()),另一个用于比较年份,使用 abs()(返回差值)。
本练习是课程的一部分
R 中级正则表达式
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Calculate the string distance - it should be smaller than 3
is_string_distance_below_three <- function(left, right) {
___(left, right) < ___
}
is_string_distance_below_three("Hi there", "Hi there")