我正在嘗試使用RecordLinkage包生成唯一的ID列。在使用較小數據集(< = 1,000,000)時,我已成功完成此操作,但未能在包中使用不同(但類似)功能的較大數據集(> 1,000,000)中重現此結果。儘管事實上在記錄中可能存在一些錯誤(接近匹配)或重複的事實,但我會爲其提供多個標識符變量,但我想生成一個唯一標識。使用RecordLinkage包爲大數據集生成唯一的ID列
鑑於標識符的一些數據幀:
data(RLdata500)
df_identifiers <- RLdata500
這是對於較小的datesets代碼(工作):
df_identifiers <- df_identifiers %>% mutate(ID = 1:nrow(df_identifiers))
rpairs <- compare.dedup(df_identifiers)
p=epiWeights(rpairs)
classify <- epiClassify(p,0.3)
matches <- getPairs(object = classify, show = "links", single.rows = TRUE)
# this code writes an "ID" column that is the same for similar identifiers
classify <- matches %>% arrange(ID.1) %>% filter(!duplicated(ID.2))
df_identifiers$ID_prior <- df_identifiers$ID
# merge matching information with the original data
df_identifiers <- left_join(df_identifiers, matches %>% select(ID.1,ID.2), by=c("ID"="ID.2"))
# replace matches in ID with the thing they match with from ID.1
df_identifiers$ID <- ifelse(is.na(df_identifiers$ID.1), df_identifiers$ID, df_identifiers$ID.1)
這種方法進行了討論here。但是,當使用其他函數應用於較大的數據集時,此代碼似乎不可擴展。例如,compare.dedup
大數據相當於是RLBigDataDedup
,其RLBigData
類支持類似的功能,如epiWeights
,epiClassify
,getPairs
等與RLBigDataDedup
更換compare.dedup
沒有在這種情況下工作。
考慮用於大型數據集的嘗試以下:
df_identifiers <- df_identifiers %>% mutate(ID = 1:nrow(df_identifiers))
rpairs <- RLBigDataDedup(df_identifiers)
p=epiWeights(rpairs)
(. . .)
在此,其餘的代碼幾乎是相同的,所述第一的。儘管epiWeights
和epiClassify
按預期在RLBigData
類上工作,但getPairs
沒有。函數getPairs
不使用show = "links"
參數。因此,所有後續代碼都不起作用。
在使用RLBigData
類中的較大數據集時,是否需要採取不同的方法來生成唯一ID列?或者這僅僅是一個限制嗎?