[R] Werid things when write.table

Damian Abalo wardamo.zero at gmail.com
Wed Sep 7 12:41:17 CEST 2011


It works now. It is much more appropiate to add the titles than to add
a column with strings, and, in fact, it were rownames, not column
names (thats why colnames was set to true). Anyway using rownames
instead of adding an aditional column and setting row.names to true in
the write.trable works perfectly.
Thanks for the help, and sorry for asking such a basic thing, I am
still not very good at R :P

2011/9/7 jim holtman <jholtman at gmail.com>:
> If your matrix is being converted to characters, then the conversion
> (and the use of '.' for decimal) is happening before the the
> write.table call.  Do the cbinding without putting titles (characters)
> in the first line and then once the table is build, use 'colnames' to
> add the titles.  It sounds like in the call you are using
> 'col.names=TRUE' so are you also getting column names in addition to
> the titles you have in the first line.  It is hard to tell without
> reproducible data, or at least an 'str' of both of the objects you
> reference.
>
> On Wed, Sep 7, 2011 at 4:10 AM, Damian Abalo <wardamo.zero at gmail.com> wrote:
>> Hello, I am having some issues with the order write.table.
>>
>> The fact is that I need to use "," as the decimal character and not
>> "." as default, and when I use:
>>
>> write.table(Sales,file="Sales.xls",quote=FALSE, sep = "\t", dec = ",",
>> row.names = FALSE, col.names = TRUE)
>>
>> It does it perfectly, but then, in a different part of the code:
>>
>> write.table(Error,file="Error report.xls",quote=FALSE, sep = "\t", dec
>> = ",", row.names = FALSE, col.names = TRUE)
>>
>> It does not do it, it keeps the . as the decimal character. The main
>> difference is that the second table is treated as a character matrix,
>> because it has characters on the first line, which work as titles.
>> This table is builded by cbinding several quantile orders, and I don't
>> know how to make the program treat the table as numbers while
>> mantaining the titles (Since it is not a table really). Any ideas?
>> Thanks for your help
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>
>
> --
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
>



More information about the R-help mailing list