簡體   English   中英

為 R 中的非排除類別創建虛擬變量

[英]Create dummy variables for non excluding categories in R

我想創建類別的二進制表示。 我知道如何排除類別(使用插入符號包),但不是針對非排除類別的直接方法。 例如

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

我們可以使用dcast

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM