如果行相同,我如何比较和表示我的两列的分类数据,如果行相同,则为 1,如果不相同,则使用 R

How can I compare and represent the categorical data of my two columns with 0 if the rows are the same and 1 if not, using R

我如何比较我的两列的分类数据,如果两列的行相同,如果不同,则用 0 可视化 1。

如果您的数据框的分类列被命名为 xy 并且具有相同的 levels 您可以为您的数据框分配一个新列,并将两者进行比较使用 ifelse 函数的列。

df$match <- ifelse(df$x == df$y, 0, 1)