Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Selected Reading
How to convert dot to comma for numerical columns in an R data frame?
Most European countries use a comma in place of a decimal. Therefore, if we have a data set that contains dot as a decimal market and we need to use that four such European countries or if dot is recorded in place of comma then we can replace the dot with comma using format function as shown in the below examples.
Example1
x2<−sample(c(501.24,502.7,501.24,503.2),20,replace=TRUE) y2<−sample(c(2.24,2.7,1.4,3.2),20,replace=TRUE) df2<−data.frame(x2,y2) df2
Output
x2 y2 1 503.20 1.40 2 502.70 2.24 3 503.20 2.70 4 503.20 3.20 5 502.70 2.24 6 503.20 2.24 7 502.70 2.24 8 501.24 1.40 9 502.70 1.40 10 501.24 2.70 11 502.70 2.24 12 502.70 3.20 13 503.20 2.70 14 502.70 2.70 15 502.70 3.20 16 503.20 2.70 17 503.20 1.40 18 502.70 1.40 19 501.24 1.40 20 502.70 2.70
Replacing dots with comma −
Example
format(df2,decimal.mark=",")
Output
x2 y2 1 503,20 1,40 2 502,70 2,24 3 503,20 2,70 4 503,20 3,20 5 502,70 2,24 6 503,20 2,24 7 502,70 2,24 8 501,24 1,40 9 502,70 1,40 10 501,24 2,70 11 502,70 2,24 12 502,70 3,20 13 503,20 2,70 14 502,70 2,70 15 502,70 3,20 16 503,20 2,70 17 503,20 1,40 18 502,70 1,40 19 501,24 1,40 20 502,70 2,70
Advertisements
