I have data that looks like this:
df <- tribble(
~name, ~value,
"Jake Lake MLP", 10,
"Bay May CE", 5,
"Drake Cake Jr. DSF", 9.1,
"Sam Ram IR QQQZ", 1
)
I want to trim all the names so that they are:
"Jake Lake",
"Bay May",
"Drake Cake Jr.",
"Sam Ram IR"
Basically removing everything after the last space.
I tried:
df %>% mutate(name = str_replace(name, "\\s.*$", ""))
But it's not quite what I want!