I have a dataframe that has multiple . separators. I wish to remove the characters after the last occurrence of . but only if it's numeric. So in the example below, a.b.c will remain intact, but a.b.1 will become two values: a.b and 1. I think I'm close but can't figure out the final piece to pull it together.
have <- data.frame(x = c("a.b", "a.b.c", "a.b.1", "a.b.2", "9.a.b.c"))
want <- data.frame(x = c("a.b", "a.b.c", "a.b", "a.b", "9.a.b.c"),
y = c(0, 0, 1, 2, 0))
# attempt 1
have %>% mutate(y = sub('.*\\.', '', x))
# attempt 2
have %>% separate(x, c('y', 'z'), sep = '.*\\.', extra = 'merge', remove = FALSE)