I have a data frame with two columns (key and value) where each column is a factor:
df = data.frame(gl(3,4,labels=c(\'a\',\'b\',\'c\')), gl(6,2)) colnames(df) =
An easy way to do it in base R:
base
res <-table(df) res[res>0] <-1 res value #key 1 2 3 4 5 6 # a 1 1 0 0 0 0 # b 0 0 1 1 0 0 # c 0 0 0 0 1 1