数据合并在r统计中

时间:2015-10-13 19:40:56

标签: r merge

我是高中的学生,在EXCEL任职。我现在想要看看这是否如何在R统计软件中解释它。这只是一个例子,但是说有文件25

File1

City    Population  GDP             
A       100         700
B       150         800 
C       80          740

File2是

City    Import      Export              
A       520         420
B       425         420 
C       200         340

File3是

City    Average Income  Average Saving              
A       10              70
B       15              80  
C       8               74

输出

City    Population  GDP   Import    Average Saving      
A       100         700    520      70
B       150         800    425      80
C       80          740    200      74

在这里输入代码

File1[,c("City","Population","GDP")]
File2[,c("City","Import")]
File3[,c("City","Average Saving")]

这就是说需要VARS并匹配城市,然后将它们组合起来就像这样做

multmerge = function(D:/FILES){
filenames=list.files(path=mypath, full.names=TRUE)
datalist = lapply(filenames, function(x){read.txt(file=x,header=T)})
Reduce(function(x,y) {merge(x, y, by = intersect(City, City),}, datalist)

0 个答案:

没有答案