I am trying to get rid of all the numbers/characters coming in AFTER the FIRST hyphen. here are some examples:
15-103025-01
800-40170-02
68-4974-01
My desired output:
15-
800-
68-
I've read through posts like these:
- Using gsub to extract character string before white space in R
- truncate string from a certain character in R
- Truncating the end of a string in R after a character that can be present zero or more times
But they are not what I'm looking for as the methods mentioned in those will get rid of my hyphen as well (leaving me only the first 2 or 3 numbers).
Here's what I've tried so far:
gsub(pattern = '[0-9]*-$', replacement = "", x = data$id)
grep(pattern = '[0-9]*-', replacement = "", x = data$id)
regexpr(pattern = '[0-9]*-', text = data$id)
but not really working as I expected.