【问题标题】: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 [closed]如果行相同,我如何比较和表示我的两列的分类数据,如果行相同,则使用 R [关闭]
【发布时间】:2020-08-06 15:27:36
【问题描述】:

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

【问题讨论】:

    标签: r if-statement compare row categorical-data


    【解决方案1】:

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

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

    【讨论】:

    • 当我想将分类列 x 与其自身、y 和 z 进行比较时怎么样。如果 x 与它自己相等,则用 0 表示它,如果它与 y 相等,如果它与 z 2 相等。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-20
    • 1970-01-01
    • 2012-09-12
    • 1970-01-01
    相关资源
    最近更新 更多