[Rd] write.table inconsistency (PR#7403)
murdoch at stats.uwo.ca
murdoch at stats.uwo.ca
Sat Dec 4 01:55:26 CET 2004
There's an as.matrix() call in write.table that means the formatting
of numeric columns changes depending on whether there are any
non-numeric columns in the table or not. For example,
> x <- data.frame(a=1:10,b=1:10)
> write.table(x,sep=',',row.names=F)
"a","b"
1,1
2,2
3,3
4,4
5,5
6,6
7,7
8,8
9,9
10,10
> x <- data.frame(a=1:10,b=as.factor(1:10))
> write.table(x,sep=',',row.names=F)
"a","b"
1,"1"
2,"2"
3,"3"
4,"4"
5,"5"
6,"6"
7,"7"
8,"8"
9,"9"
10,"10"
Notice that column "a" has a leading space in the second example, but
not the first.
Normally this won't matter, but RSQLite uses write.table in the
sqliteWriteTable function, which would cause column "a" above to be
treated as text rather than numeric, and be sorted as text rather than
into numerical order.
Duncan Murdoch
More information about the R-devel
mailing list