[R] inconsistant decimal marker with write.table

Denis Chabot
Tue, 13 Sep 2005 19:53:39 -0000

Hi,

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:

"trait";"tfi";"sto_wt";"pfi2";"pfi_st";"focc";"sed";"mob";"date";"latitu
de";"longitud";"hre_deb";"temp_fon";"strate";"lat.km";"long.km";"temp_.2
5C"
10;0,764;5,1;0.007;0,213;0,143;0,048;0,095;"05/08/99";
47,49;-58,9267;"20:11";4,9;302;-167,791200000000;230,761439786593;4,88
106;0,566;3,3;0.089;4,762;0,25;0;0,25;"14/08/99";
49,84;-59,655;"23:25";4,4;814;93,3408000000004;168,052052432345;4,38
110;1,517;8,3;0.003;0,172;0,25;0;0;"15/08/99";
49,88667;-60,2167;"04:57";0,3;833;98,5267704000003;127,674990442535;0,38
111;1,232;7,5;0.016;1,309;0,25;0;0;"15/08/99";49,84;-60,1617;"06:14";
0,1;833;93,3408000000004;131,739909589075;0,12

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,

Sincerely,

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