如何比较 R 中的两个 csv 文件?
How can I compare two csv file in R?
我有两个 csv 文件,A 和 B。
我想找出 A 和 B 之间不同列的数量。
例如,假设 A 包含 7、9、0、0、2,B 包含 7、8、6、0、2(因此 A 和 B 各有五列)。
那么,不同列的个数为2,第二列和第三列。
我如何在 R 上实现它?
你可以试试
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
数据
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 文件,A 和 B。
我想找出 A 和 B 之间不同列的数量。
例如,假设 A 包含 7、9、0、0、2,B 包含 7、8、6、0、2(因此 A 和 B 各有五列)。 那么,不同列的个数为2,第二列和第三列。
我如何在 R 上实现它?
你可以试试
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
数据
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))