I have values where some have a period (.) in the end, here 95.2. and 87.5.:
c("25.3", "95.4", "95.6", "95.2.", "87.5.")
How can I remove the trailing periods? Desired result:
c(25.3, 95.4, 95.6, 95.2, 87.5)
We can use sub to match the dot (. - is a metacharacter meaning any character - so we either escape (\\.) or place it in a square bracket to evaluate as the dot character) at the end ($) of the string and replace it with blanks, then convert it to numeric
as.numeric(sub("[.]$", "", dat$Col))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With