Pages

Friday, November 15, 2013

How to Convert Number Values that Include Commas From Character to Numeric in R

Sometimes when importing data into R, especially from Excel spreadsheets, there are comma separators between every three digits to more clearly delineate the size of the number.  While this is convenient visually, when importing such numbers into R it can be a bit of a headache trying to convert these numbers from character format into an analysis friendly numeric format.  Here is a quick one liner of code to convert such an imported variable from character to numeric:


Essentially, this code first removes all commas by replacing them with nothing, then converts the numbers from character format to numeric format, and finally replaces the original variable with the new one.

No comments:

Post a Comment