When it's "25,890", it appears "25,89"

Hello,

I have imported a document like this read.csv("*****.csv",sep=";",header=T), I have a problem with the numbers, when it's "25,890", it appears "25,89", do you have any idea to resolve it ?

Thank you in advance

Hi,

I guess the commas are thousand separators? If so, you would have to remove them after import. Here's a link on how to: https://stackoverflow.com/questions/1523126/how-to-read-data-when-some-numbers-contain-commas-as-thousand-separator?noredirect=1&lq=1

Cheers
Steeen

1 Like

Yes it is the thousand separators.
I tried the solutions of the link but "25,890" becomes "2 589" instead of "25 890".

You probably have to make sure that you read the values as characters in order to avoid any conversions done during the reading. You can control the data type of the columns with the parameter colClasses.

1 Like

Consider package readr - it is is faster than the base equivalent and gives you more control.

I expect that this code should give you the result you seek:

readr::read_delim("path-to-yer-file.csv", delim = ";", 
                  locale = readr::locale(decimal_mark = ".", 
                                         grouping_mark = ","))
3 Likes

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.