I have a dataframe as follows:
df <- data.frame(s1=c("a","a/b","b","a","a/b"),s2=c("ab/bb","bb","ab","ab","bb"),s3=c("Doa","Doa","Dob/Doa","Dob/Doa","Dob"))
s1 s2 s3 1 a ab/bb Doa 2 a/b bb Doa 3 b ab Dob/Doa 4 a ab Dob/Doa 5 a/b bb Dob
Each column could take one of two values or both separated by a "/". I would like to break these down into binary sets of columns based on their values.
The desired data frame would be:
a b ab bb Doa Dob 1 1 0 1 1 1 0 2 1 1 0 1 1 0 3 0 1 1 0 1 1 4 1 0 1 0 1 1 5 1 1 0 1 0 1
I tried doing this with tidyr::separate and tapply, though it got fairly complicated as I had to specify column names for every pair. There were many columns.