Convert numeric values into binary (0/1)

后端 未结 5 1705
余生分开走
余生分开走 2021-02-06 08:15

I have a data frame with counts of different kinds of fruits of different people. Like below

    apple  banana  orange
Tim     3       0       2
Tom     0                


        
5条回答
  •  星月不相逢
    2021-02-06 08:52

    Just use a comparison:

    d = t(matrix(c(3,0,2,0,1,1,1,2,2), 3))
    d > 0
    t(matrix(as.numeric(d>0), ncol(d)))
    

提交回复
热议问题