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
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)))