Welcome to the Genome Toolbox! I am glad you navigated to the blog and hope you find the contents useful and insightful for your genomic needs. If you find any of the entries particularly helpful, be sure to click the +1 button on the bottom of the post and share with your colleagues. Your input is encouraged, so if you have comments or are aware of more efficient tools not included in a post, I would love to hear from you. Enjoy your time browsing through the Toolbox.

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