I have a dataframe like this
df <-data.frame(id = c(1,2), value = c(25,24), features = c(\"A,B,D,F\",\"C,B,E\")) print(df) i
A dplyr/tidyr solution
library(dplyr) library(tidyr) separate(df,features,1:4,",",extra="merge") %>% gather(key,letter,-id,-value) %>% filter(!is.na(letter)) %>% select(-key) %>% mutate(n=1) %>% spread(letter,n) %>% mutate_each(funs(ifelse(is.na(.),0,1)),A:F)