[R] inconsistant decimal marker with write.table

Denis Chabot chabotd at globetrotter.net
Tue Sep 13 21:53:39 CEST 2005


My problem does not happen all the time, nor with all files I save to  
csv format. I can send my test file (format rda or csv) to whoever  
would like to replicate (and hopefully explain) my problem.

In short, I have a dataset with mostly numerical variables. One of my  
variable is called pfi2 and is definitely numerical, as shown by this:

 > summary(test$pfi2)
    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
0.00000 0.00000 0.00000 0.01208 0.01500 0.08900

Yet, when I export to a text file and asking for comma as the decimal  
separator, I get a period as the separator for this variable, whereas  
all the other variables have the desired comma as separator.

write.table(test, "out1.csv", sep = ";", dec = ",", row.names = F,  
col.names = TRUE)
write.csv2(test, "out2.csv")

First 5 lines of out1.csv:


I'm sorry but I wanted to make this lighter by removing more  
variables from my original dataset, but the problem disappeared, so I  
had to keep these variables to show you the problem SOMETIMES happen.  
You'll notice that the 4th variable has periods for decimal markers.  
The write.csv2 command produced the same problem.

With other files I sometimes get commas for all variables, sometimes  
I get more than one variable with periods. It is frustrating.

So let me know if you'd like the data file,


Denis Chabot
platform powerpc-apple-darwin7.9.0
arch     powerpc
os       darwin7.9.0
system   powerpc, darwin7.9.0
major    2
minor    1.1
year     2005
month    06
day      20
language R

More information about the R-help mailing list