I would like to convert an alphanumeric vector to a numeric vector. Right now I'm using regex, but with 2 calls gsub:
to_numeric <-
function(x) gsub(',','.',gsub("[^(\\d|,)]","",x,perl=TRUE))
to_numeric(c('a12,12','Atr 145 ',' 14 5,1 4A'))
How can I simplify this for a single call using a unique regular expression or any other method? Thanks in advance.
source
share