in R, Dec="," does not work in read.csv2

Asked

Viewed 197 times

2

Good afternoon to you... I’m trying to import csv where decimals are separated by dots... or something like 2.5

I want when it’s time to import it to show up with a comma, something like that, 2.5

 uo_14<- read.csv2("csv\\uo_2014.csv", as.is = FALSE , header = TRUE, 
                     sep = ",", dec=",", encoding='UTF-8' )


 uo_14
    nome   valor1  valor 2
    nome1   3.5      3.6
    nome2   5.4      1.7

I don’t know what the problem is!

  • I don’t think you can use the same column and decimal separator

1 answer

3


If the goal is only to change the way the output of R displays the decimal separator, you can use:

options(OutDec = ",")

See the description of the option Outdec in the function help page options (?options) for more information.

Also, if your csv file uses dot as decimal separator then you should use dec = "." in function read.csv2:

uo_14 <- read.csv2("csv\\uo_2014.csv", as.is = FALSE, header = TRUE, 
                 sep = ",", dec = ".", encoding='UTF-8')

Browser other questions tagged

You are not signed in. Login or sign up in order to post.