Fhnuzoag Fhnuzoag - 2 months ago 27
R Question

as.numeric with comma decimal separators?

I have a large vector of strings of the form:

Input = c("1,223", "12,232", "23,0")

etc. That's to say, decimals separated by commas, instead of periods. I want to convert this vector into a numeric vector. Unfortunately,
just outputs

My first instinct would be to go to
, but it seems to me that this will likely be very slow. Does anyone have any idea of a faster option?

There's an existing question that suggests
, but the strings in question are not directly read in that way.

as.numeric(sub(",", ".", Input, fixed = TRUE))

should work.