我想将数据帧df1转换为数据帧df2.
id <- c(1,2,3)
outcome_1 <- c(1,0,1)
outcome_2 <- c(1,1,0)
df1 <- data.frame(id,outcome_1,outcome_2)
id <- c(1,2,3)
outcome <- c("1,2","2","1")
df2 <- data.frame(id,outcome)
以下问题的答案几乎符合我的要求,但在我的情况下,一行可以有多个积极结果(例如,第一行需要是"1,2").此外,我希望生成的列是字符列.
R: Converting multiple binary columns into one factor variable whose factors are binary column names
请帮忙.非常感谢.