R 关于比较矩阵,包括单词/字符

R 关于比较矩阵,包括单词/字符,r,R,我从不同的csv文件中提取了两个矩阵 一个是 > matrix1[1:6,] V1 V2 1 atheism 1.0000000 2 rec 1.0000000 3 alt 1.0000000 4 baseball 1.0000000 5 sport 1.0000000 6 season 0.4934226 另一个是 >matrix2[1:6,] V1 V2 1

我从不同的csv文件中提取了两个矩阵

一个是

> matrix1[1:6,]
     V1        V2
 1   atheism 1.0000000
 2       rec 1.0000000
 3       alt  1.0000000
 4  baseball 1.0000000
 5     sport 1.0000000
 6    season 0.4934226
另一个是

>matrix2[1:6,]
         V1        V2
 1       alt 1.0000000
 2   atheism 1.0000000
 3  baseball 1.0000000
 4       rec 1.0000000
 5     sport 1.0000000
 6         c 0.4934226
我想做的是比较两个矩阵,这就是我做的

mapply(as.data.frame(test1),as.data.frame(test2),FUN=function(v1,v2) all(v2==v2))
        V1   V2 
       TRUE TRUE
然而,我需要的是捕获两个数据集之间第一列中的差异,但是我没有捕获字符串中的差异,即如何修改代码。谢谢。

也许可以试试:

union(test1[, 1] , test2[, 1])    #the same (together)
intersect(test2[, 1], test1[, 1]) #overlap
union(test1[, 1] , test2[, 1]) [!union(test1[, 1] , test2[, 1]) %in% intersect(test2[, 1], test1[, 1])]
setdiff(test1[, 1] , test2[, 1])  #diff in set 1
setdiff(test2[, 1] , test1[, 1])  #diff in set 2