df <- data.frame(
strings = c('blah?ha', 'foo?bar', 'cats?dogs')
)
df %>%
mutate(first_word = str_split(strings, fixed('?')))
strings first_word
strings first_word
1 blah?ha blah, ha
2 foo?bar foo, bar
3 cats?dogs cats, dogs
This gets me close to my goal. I just want the first part though, blah, foo and cats. Tried:
df %>%
+ mutate(first_word = str_split(strings, fixed('?'))[[1]][[1]])
strings first_word
1 blah?ha blah
2 foo?bar blah
3 cats?dogs blah
This gives me the same word repeated down the column.
How can I get a new column with the values blah, foo and cats?