我正在使用R中的plyr包来执行以下操作:
我已经制作了进度条来显示进度,但是在它显示到100%之后,它似乎还在运行,因为我已经看到我的CPU仍然被RGUI占用,但是它没有结束。
我的表A有大约40000行数据,有唯一的A列和B列。
我怀疑plyr中的“拆分-征服-组合”工作流中的“组合”部分无法处理这40000行数据,因为我可以为另一个拥有4000行数据的表处理。
有提高效率的建议吗?谢谢。
更新
这是我的代码:
for (loop.filename in (1:nrow(filename)))
{print("infection source merge")
print(filename[loop.filename, "table_name"])
temp <- get(filename[loop.filename, "table_name"])
temp1 <- ddply(temp,
c("HOSP_NO", "REF_DATE"),
function(df)
{temp.infection.source <- abcde[abcde[,"Case_Number"]==unique(df[,"HOSP_NO"]) &
abcde[,"Reference_Date"]==unique(df[,"REF_DATE"]),
"Case_Definition"]
if (length(temp.infection.source)==0) {
temp.infection.source<-"NIL"
} else {
if (length(unique(temp.infection.source))>1) {
temp.infection.source<-"MULTIPLE"
} else {
temp.infection.source<-unique(temp.infection.source)}}
data.frame(df,
INFECTION_SOURCE=temp.infection.source)
},
.progress="text")
assign(filename[loop.filename, "table_name"], temp1)
}发布于 2010-10-21 10:07:32
如果我正确地理解了你想要达到的目标,这应该能做你想做的事,而且速度很快,而且不会有太多的记忆损失。
#toy data
A <- data.frame(
A=letters[1:10],
B=letters[11:20],
CC=1:10
)
ord <- sample(1:10)
B <- data.frame(
A=letters[1:10][ord],
B=letters[11:20][ord],
CC=(1:10)[ord]
)
#combining values
A.comb <- paste(A$A,A$B,sep="-")
B.comb <- paste(B$A,B$B,sep="-")
#matching
A$DD <- B$CC[match(A.comb,B.comb)]
A这只适用于组合是唯一的。如果他们不是,你得先处理好。没有这些数据,就不可能准确地知道您想要实现的全部功能,但是您应该能够将这里给出的逻辑移植到您自己的情况中。
https://stackoverflow.com/questions/3985242
复制相似问题