I'm trying to do a binary transformation of a comma separated string column in a data frame that looks like this:
df <- data.frame(id = c(1,2,3),
mystring = c("test1,test2", "test2,test3", "test1"))
print(df)
id mystring
1 1 test1,test2
2 2 test2,test3
3 3 test1
I want to achieve a binary transformation like:
df_result <- data.frame(id = c(1,2,3),
test1 = c(1,0,1),
test2 = c(1,1,0),
test3 = c(0,1,0))
print(df_result)
id test1 test2 test3
1 1 1 1 0
2 2 0 1 1
3 3 1 0 0