I would like to clean this vector and only retain the digits
vec = c(" 4010 \"Filling in time budget diary\"", " 8888 \"Prob cont. preceding activity\"", " 9999 \"Missing, undecipherable\";")
what I would like is simply : 4010, 8888, 9999
I thought of something like, matching exactly the digits but it doesn't work.
gsub("^[[:digit:]]$", replacement = '', vec)
Thanks
We can use \\D+
to match all non-numeric elements and replace with ''
gsub('\\D+','', vec)
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