I am trying to split a column of comma separated characters into several columns (as many as different characters overall). I read similar questions such as this:
Split data frame string column into multiple columns
But the solutions were based on a small number of possible characters, so that the new columns could be named in advanced before the columns was split.
This is my example:
subject <- c(1,2,3) letters <- c("a, b, f, g", "b, g, m, l", "g, m, z") df1 <- data.frame(subject, letters) df1 subject letters 1 1 a, b, f, g 2 2 b, g, m, l 3 3 g, m, z The desired result would be:
subject a b f g m z 1 1 1 1 1 1 0 0 2 2 0 1 0 1 1 0 3 3 0 0 0 1 1 1 Thanks in advance for any help.