1

in R, when using

write.csv(df, file = "/path/dataframeX.csv",row.names=FALSE, fileEncoding = "UTF-8")

and then reading the csv with

read.csv("/path/dataframeX.csv", header = T, na.strings=c(""," ","NA"))

it changes my point separated values to comma separated values (e.g. 4.32 becomes 4,32). Is there a way to avoid this? What mistake am I doing?

edit: solved - add dec = "," to the read.csv()

Thank you very much and best regards,

Jimmy

JimmysCheeseSteak
  • 123
  • 1
  • 2
  • 8
  • What locale are you using. What does `sessionInfo()` show? Where exactly is the change taking place? What does R show? What is actually written to the csv file? It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Oct 26 '18 at 16:00
  • 1
    Some other bits of information that might help: `Sys.getlocale()` and `options("OutDec")`. Note that there are really two things at play here wrt which character is used for the decimal separator: reading CSV files (e.g., `read.csv` vs `read.csv2`); writing CSV files (similar); and *displaying* numbers with fractional components (e.g., `options(OutDec=",")` vs `options(OutDec=".")`). Unless your `4,32` is being returned as `character`, then its most likely the last one, `options("OutDec")` that's to "blame". – r2evans Oct 26 '18 at 16:09
  • Found the solution myself: in the `read.csv()` add `dec = ","` :) – JimmysCheeseSteak Oct 26 '18 at 16:09

0 Answers0