在R中:查找两组列之间的百分比匹配

在R中:查找两组列之间的百分比匹配,r,R,全部。我是R的新手。我的数据集如下所示: SUBJ STIM A1 A2 A3 A4 W1 W2 W3 W4 26 1 I26 call to other classes copy extra class notes 27 1 I27 cats should go grass cow chewed

全部。我是R的新手。我的数据集如下所示:

    SUBJ STIM      A1        A2       A3      A4      W1      W2       W3      W4
26     1  I26    call        to    other classes    copy   extra    class   notes
27     1  I27    cats    should       go   grass     cow  chewed     long   grass
28     1  I28   crowd    yelled      out   cheer   crowd  yelled      out   cheer
29     1  I29     dad    drinks      hot     tea     dad  drinks      hot     tea
其中W1-W4为预测值,A1-A4为实际值。我想找出实际值的“正确”百分比,即A1-A4列作为一个组与W1-W4列作为一个组之间的匹配。行顺序很重要

我能够使用

paste0(round(100*length(intersect(dataset$A1, dataset$W1))/nrow(dataset)), "%")
从这里的另一个问题可以得到A1列和W1列之间的行匹配百分比,但必须有一种有效的方法来查找A列和W列作为组之间的匹配


谢谢大家!

您可以将数据子集到A列,然后再到W列,检查与
=
相同的数据,然后获得与
平均值相同的百分比

pct <- mean(df[, paste0('A', 1:4)] == df[, paste0('W', 1:4)])
pct
# [1] 0.5625
scales::percent(pct)
# [1] "56.2%"
pct