【问题标题】:Create dummy variables for non excluding categories in R为 R 中的非排除类别创建虚拟变量
【发布时间】:2016-10-15 16:37:45
【问题描述】:

我想创建类别的二进制表示。我知道如何排除类别(使用 caret 包),但不是一种直接的方法来排除非排除类别。比如

movies <- data.table(movie=c( "batman", "bighero6"), type=list("action",c("action","animation"))) movie type 1: batman action 2: bighero6 action,animation

我想获得类似的东西 action animation batman 1 0 bighero6 1 1

【问题讨论】:

    标签: r dummy-variable


    【解决方案1】:

    我们可以使用dcast

     dcast(movies[,.(type=unlist(type)) ,movie], movie~type, length)
    

    【讨论】:

    • 完美运行。非常感谢
    猜你喜欢
    • 2019-05-19
    • 2020-04-03
    • 2023-03-24
    • 2013-09-23
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多