I have string like this:
years<-c(\"20 years old\", \"1 years old\")
I would like to grep only the numeric number from this vector. Expe
Update Since extract_numeric is deprecated, we can use parse_number from readr package.
extract_numeric
parse_number
readr
library(readr) parse_number(years)
Here is another option with extract_numeric
library(tidyr) extract_numeric(years) #[1] 20 1