如何比较两个csv文件在R? [英] How can I compare two csv file in R?
本文介绍了如何比较两个csv文件在R?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个csv文件,A和B.
我想查找A和B之间不同列的数字。
例如,假设A包含7,9,0,0,2,B包含7,8,6,0,2(因此A和B各有五列)。
然后,不同的列的数量是2,第二和第三列。
如何在R上实现?
解决方案
您可以尝试
indx< - colSums (!indx)#get索引(!indx)#get不同列的索引
#Col2 Col3
#2 3
的类似列
#Col1 Col4 Col5
#1 4 5
length(which(!indx))
#[1] 3
data
A < (Col1 = c(7,2),Col2 = c(9,4),Col3 = c(0,5),
Col4 = c(0,3) )
B < - data.frame(Col1 = c(7,2),Col2 = c(8,4),Col3 = c(6,5),
Col4 = c 3),Col5 = c(2,3))
I have two csv file, A and B.
I want to find the number of different column between A and B.
For example, let's assume that A contains 7, 9, 0, 0, 2 and B contains 7,8,6,0,2 ( so A and B have five column each). Then, the number of different column is 2, the second and third column.
How can I implement this on R?
解决方案
You could try
indx <- colSums(A!=B)
which(!!indx) #gets the index of different columns
# Col2 Col3
# 2 3
which(!indx) #gets the index of similar columns
#Col1 Col4 Col5
# 1 4 5
length(which(!indx) )
#[1] 3
data
A <- data.frame(Col1= c(7,2), Col2= c(9,4), Col3= c(0,5),
Col4= c(0,3), Col5=c(2,3))
B <- data.frame(Col1= c(7,2), Col2= c(8,4), Col3= c(6,5),
Col4= c(0,3), Col5=c(2,3))
这篇关于如何比较两个csv文件在R?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文