我有这个代码
dataframe = data.frame(nam= c("stefy, dany", "dany, ari", "ale"), num = c(1,2,3))
dim(dataframe)
library(qdapTools)
dataframe$nam = gsub(" ", "", dataframe$nam, fixed = TRUE)
names1 = mtabulate( strsplit(dataframe$nam, ','))
names1
myNames = names(names1) # 29 total Genre
myNames
dataframe$nam = apply( names1 , 1 , paste , collapse = "," )
dataframe
数据看起来像这样
这
nam num
1 stefy,dany 1
2 dany,ari 2
3 ale 3
要
ale ari dany stefy
1 0 0 1 1
2 0 1 1 0
3 1 0 0 0
> myNames = names(names1)
> myNames
[1] "ale" "ari" "dany" "stefy"
要
nam num
1 0,0,1,1 1
2 0,1,1,0 2
3 1,0,0,0 3
有一种快速的方法可以将二进制矢量/指标变量与可能值的字典相关联。 此外,如果我想创建一个情节,我想看到字符串不是二进制矢量 谢谢