I need to concatenate the previous and the latter words of a condition meeting word. Specifically, those who match the condition of having a comma.
vector <- c("Paulsen", "Kehr,", "Diego", "Schalper", "Sepúlveda,", "Diego")
#I know how to get which elements meet my condition:
grepl(",", vector)
#[1] FALSE TRUE FALSE FALSE TRUE FALSE
Desired output:
print(vector_ok)
#[1] "Paulsen Kehr, Diego", "Schalper Sepúlveda, Diego"
Thanks in advance!