[R] read.table, row.names arg

Adrian Dusa dusa.adrian at gmail.com
Fri Jun 5 18:19:13 CEST 2009


Markus Loecher <markus.loecher <at> gmail.com> writes:

> [...]
> > x
>                   ID X1 X2
> 1 010007787048271871  1  4
> 2   1007109516820319  2  3
> 3  10094843652996959  3  2
> 4 010145176274075487  4  1
> 
> The first column was not read in as a string, which mangled the IDs.
> I could use colClasses explicitly, but then I would need to know the number
> and classes of the remaining columns in advance.
> Is this a bug or expected behavior ?
> Any advice would be most helpful.

You could use a generic colClasses for all columns, like:

y <- read.table("tmp.txt", header= TRUE, row.names=1, colClasses="character")
y
                   X1 X2
010007787048271871  1  4
1007109516820319    2  3
10094843652996959   3  2
010145176274075487  4  1

In this case, all columns are read as character and need to be converted
manually, but your row names are appropriate.

Hoping this helps,
Adrian




More information about the R-help mailing list