Re: [問題] 多個檔案合併 取聯集

作者: gsuper (Logit(odds))   2014-07-11 14:40:20
VAR <- list(NULL) ; x=1
VAR[[x]]<-data.frame(day1=c(23,45,100),names=c("A","B","D")) ; x=x+1
VAR[[x]]<-data.frame(day2=c(77,11,35) ,names=c("A","C","D")) ; x=x+1
VAR[[x]]<-data.frame(day3=c(11,44,55) ,names=c("B","D","E")) ; x=x+1
ROW <- sort(unique(as.character(sapply(VAR,function(s){s[,"names"]}))))
PLATE <- data.frame(rep(NA,length(ROW)),names=ROW)
res <- sapply(VAR,function(s){merge(PLATE,s,by="names",all=TRUE)[,3]})
res[is.na(res)] <- 0
rownames(res) <- ROW
colnames(res) <- sapply(VAR,colnames)[1,]

Links booklink

Contact Us: admin [ a t ] ucptt.com