我需要从调查数据中制作一个假人数据框,其中受访者在数据框中的几列中陈述了单词。这是一个简化的示例来说明我需要做什么?一个单词在这里用一个字母表示。
id <- c(1:6)
v.1 <- c("a","b","d","e","a","c")
v.2 <- c("b","a","a","a","b","a")
v.3 <- c("e","c","b","b","e","b")
df <- data.frame(id,v.1,v.2,v.3)
> df
id v.1 v.2 v.3
1 1 a b e
2 2 b a c
3 3 d a b
4 4 e a b
5 5 a b e
6 6 c a b
这是我想要的输出?
> print(df.dummy)
id a b c d e
1: 1 1 1 0 0 1
2: 2 1 1 1 0 0
3: 3 1 1 0 1 0
4: 4 1 1 0 0 1
5: 5 1 1 0 0 1
6: 6 1 1 1 0 0
有任何想法吗?