我想使用R从已知关系列表中生成一个关系矩阵。例如,使用以下数据集:
John Green
Mary Blue
Mary Red
John Blue我想要:
Green Blue Red
John 1 1 0
Mary 0 1 1我不知道该怎么做。提前感谢您的任何建议。
发布于 2012-07-10 17:57:08
您可以使用table。
people <- c("John", "Mary", "Mary", "John")
cols <- c("Green", "Blue", "Red", "Blue")
df <- data.frame(people, cols)
table(df)
cols
people Blue Green Red
John 1 1 0
Mary 1 0 1https://stackoverflow.com/questions/11410764
复制相似问题