I have a dataframe that consists of multiple rows, and I would like to split every row into two components based off of elements of a vector (essentially run strsplit with a vector as the 'pattern') in R.
The dataframe (only one column) looks something like this:
[,1]
[1,] "apple please fuji"
[2,] "pear help name"
[3,] "banana me mango"
Whereas my pattern vector could look like this: v <- c("please", "help", "me")
.
If possible, I would like my end output to be:
df$name df$part1 df$split df$part2
"apple please fuji" "apple" "please" "fuji"
"pear help name" "pear" "help" "name"
"banana me mango" "banana" "me" "mango"
I would appreciate any help with the in-between step of being able to isolate components based on a vector, but if there is an even easier way to put it into a dataframe, that would be great!. Thank you so much!