And*_*sil 5 r stringdist fuzzyjoin
我有一个 130 万行的出版物数据集,对于每条记录,我想从第二个包含 860 万行的数据集中检索 paper_id。这个想法是使用两个表中的多个列来查找 dataset2 中 dataset1 的匹配项,如这个功能性但简化的脚本所示:
library(fuzzyjoin); library(tidyverse)
dataset1 %>%
stringdist_left_join(dataset2 %>% select(Title, Year, Publication_id, Paper_id),
by = list(x = c("Title", "Year", "Publication_id"),
y = c("Title", "Year", "Publication_id"))
max_dist = 3, ignore_case = TRUE, distance_col = NULL)
Run Code Online (Sandbox Code Playgroud)
我这里有两个问题。首先,只有“标题”具有需要模糊匹配的变体(拼写错误、缩写、特殊字符等),但代码接受所有三个使用字段中的变体。这增加了可能与错误匹配的数量,因为类似的标题出现在不同的年份和出版物中。
我认为可以解决第一个问题的解决方案是:
library(fuzzyjoin); library(tidyverse)
dataset1 %>%
stringdist_left_join(dataset2 %>%
select(Title2 = Title, Year2 = Year, Pub_id2 = Publication_id, Paper_id),
by = list(x = c("Title", "Year", "Publication_id"),
y = c("Title2", "Year2", "Pub_id2"))
max_dist = 3, ignore_case = TRUE, distance_col = NULL) %>%
filter(Year == Year2, Publication_id == Pub_id2)
Run Code Online (Sandbox Code Playgroud)
这可以解决第一个问题,但还有第二个问题:脚本在样本数据上运行正常,但是当我尝试将它用于整个数据集时,它会给出错误“向量内存耗尽(达到限制?)”。
所以,我的问题是:
是否可以确定哪些列应该相同,哪些列应该模糊,这可能会使脚本变得更轻?
是否有可能根据相同的变量对两个数据集进行子集化,然后对子集中的标题运行模糊匹配,将所有内容合并回来?(我不确定这是否可行,因为我将拥有 18 万个子集:六年中的 3 万篇出版物)。
任何帮助表示赞赏。
最好的
| 归档时间: |
|
| 查看次数: |
900 次 |
| 最近记录: |