r - 如何在不遇到内存问题的情况下对几百万行进行 vlookup?
问题描述
希望编写可以执行 vlookup 的代码。
我有几个充当查找表的 excel 文件(每个包含 ~1m 行(excel 文件限制)。
然后,我有一个包含两列需要查找的 excel 表——这两列不能合并,因为结果必须分开。
首先,我加载包含要查找的表的文件:
All <- lapply(filenames_list,function(filename){
print(paste("Merging",filename,sep = " "))
read.xlsx(filename)
})
df <- do.call(rbind.data.frame, All)
然后我加载我要查找的文件:
LookUpID1 <- read.xlsx(paste(current_working_dir,"/LookUpIDs.xlsx", sep=""), sheet = 1, startRow = 1, colNames = TRUE, cols = 1, skipEmptyRows = TRUE, skipEmptyCols = TRUE)
LookUpID2 <- read.xlsx(paste(current_working_dir,"/LookUpIDs.xlsx", sep=""), sheet = 1, startRow = 1, colNames = TRUE, cols = 2, skipEmptyRows = TRUE, skipEmptyCols = TRUE)
我需要加载文件两次,因为我需要在第 1 列和第 2 列上执行查找。
然后是实际的vlookup:
# Matching ID
FoundIDs1 <- merge(df, LookUpID1)
FoundIDs2 <- merge(df, LookUpID2)
FoundIDs <- merge(FoundIDs1, FoundIDs2, by = NULL)
问题是我的电脑在运行代码的最后一部分(实际的 Vlookup)时内存不足;
错误:无法分配大小为 1715.0 Gb 的向量
解决方案
推荐阅读
- powershell - 如何使用凭证调用存储在字符串中的powershell命令?
- ios - 在 Xcode 10 中构建时重置应用程序后,String.hashValue 不唯一
- python - 如何替换 django 模板中的某些特定字符?
- angular - Ngmodel 值更新错误?
- x264 - 为什么 pkg-config 用另一个默认值覆盖“前缀”?
- cockroachdb - pq:集群版本不支持 JSONB(需要>= 2.0)
- python - 如何在python中返回连接列表?
- oracle - 表达 '
' 不能用作赋值目标 - python - 在python中的networkx图中找到最大加权边
- vba - 用于将嵌入的 Word 文档保存为 PDF 的 Excel 宏