How can I compare two csv file in R?

倾然丶 夕夏残阳落幕 提交于 2019-12-13 07:59:32

问题


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?


回答1:


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))


来源:https://stackoverflow.com/questions/29457222/how-can-i-compare-two-csv-file-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!