Fhnuzoag Fhnuzoag - 1 year ago 174
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.

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

should work.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download