I have a dataframe that looks like this:
df <- data.frame(text=c('my_text', 'looks_like_this', 'I_want_to_split_it'))
I want to use some kind of dplyr
family function to make a dataframe that looks like this:
newdf <- data.frame(text=c('my_text', 'looks_like_this', 'I_want_to_split_it'),
W1=c('my', 'looks', 'I'),
W2=c('text', 'like', 'want'),
W3=c(NA, 'this', 'to'),
W4=c(NA, NA, 'split'),
W5=c(NA, NA, 'it'))
I'm thinking something like this:
newdf <- df %>%
mutate(WX=strplit(text, '_'))
But cant quite figure it out.