Convert Numbers with Comma Separator to Numeric in R (Example Code)
In this R tutorial you’ll learn how to change thousand separators from comma to point.
Example Data
x <- "11,222" # Constructing example data object x # Printing example data object # [1] "11,222" |
x <- "11,222" # Constructing example data object x # Printing example data object # [1] "11,222"
Example: Adjusting Data Object with Comma as Thousand Separator
x_new <- as.numeric(gsub(",", "", x)) # Modifying example data object x_new # Printing new data object # [1] 11222 |
x_new <- as.numeric(gsub(",", "", x)) # Modifying example data object x_new # Printing new data object # [1] 11222