Converting multiple boolean columns to single factor column

后端 未结 4 388
伪装坚强ぢ
伪装坚强ぢ 2020-12-12 03:02

my data frame look like this:

      A S1 S2 S3 S4
1   ex1  1  0  0  0
2   ex2  0  1  0  0
3   ex3  0  0  1  0
4   ex4  1  0  0  0
5   ex5  0  0  0  1
6   ex6         


        
4条回答
  •  暖寄归人
    2020-12-12 03:34

    Could also do (if dat is your data set)

    library(reshape2)
    dat <- melt(dat, id = "A")
    dat[dat$value > 0, 1:2]
    

提交回复
热议问题