I`m trying to transform a column into multiple columns.
This is my example:
df <- data.frame(Id = c(1,2,3),
Col2 = c("['aaa' 'aaa aaaa' 'aaa.bb']","['aaa' 'aaa aaa' 'aaa bbb ccc' 'aaa'\n]","[]"))
df
Id Col2
1 ['aaa' 'aaa aaaa' 'aaa.bb']
2 ['aaa' 'aaa aaa' 'aaa bbb ccc' 'aaa'\n]
3 []
In my real case i can have 20 strings in each observation.
This would be my expected result:
df2 <- data.frame(Id =c(1,2,3),
Col1 = c("aaa","aaa",NA),
Col2 = c("aaa.aaaa","aaa.aaa",NA),
Col3 = c("aaa.bb","aaa bbb ccc",NA),
Col4 = c(NA,"aaa",NA))
df2
Id Col1 Col2 Col3 Col4
1 aaa aaa.aaaa aaa.bb NA
2 aaa aaa.aaa aaa bbb ccc aaa
3 NA NA NA NA
How can i separate by ""?
I tried to use separate function, but i can't seem to find the right sintax for "sep". "separate" seemed the best alternative for me, because I was using dplyr to maintain some previous columns.
Also, where can i find information about the using of sep. I haved saw some examples here, but I can't understand the rationale for using the characters
I also tried str_split, but i'm having trouble turning it back into a data frame.
Thanks in advance