1

I'm reading a csv and I have a problem with American and European numerical formats. American have . for decimals and European for thousands. This is the reading csv routine.

read.csv("data.csv",header=F,skip=4, sep=";", fileEncoding= "cp1252")

The thing is when I have a number finished with 0, without decimals.

> 2.100 
[1] 2.1

Imagine also:

> 2.113
[1] 2.113

I substituted, . for blank and I have an European number, but in the other case I have 21.

Also I tried some changes, but i have some digits with , and I tried to use decimal and it didn't work.

EDIT:

What arrive at df.

2.100   21.882,30

gsub("\.", "", number); gsub("\,", ".", number);

I make some transformations, after:

2.100   21882.30

R thinks it's a 2,1 but it was a 2100, the read.csv2 doesn't work.

  • 4
    `read.csv` is for American-style CSV files. `read.csv2` is for European-style CSV files. It will probably solve your issue. – Thomas May 08 '14 at 09:53

1 Answers1

2

You may also use dec to specify which symbol you want for the decimal place. For example, if the decimal sign is .:

read.csv("data.csv",header=F,skip=4, sep=";", fileEncoding= "cp1252",  dec = ".")
Thomas
  • 43,637
  • 12
  • 109
  • 140
catindri
  • 384
  • 5
  • 14