Dear R users,
I had somehow expected that read.table() would treat the column specified by
the row.names argument as of class character. That seems to be the only
sensible class allowed for a column containing row names. However, that does
not seem to be the case, as the following example shows:
x <- cbind.data.frame(ID = c("010007787048271871", "1007109516820319",
"10094843652996959", "010145176274075487"), X1 = 1:4, X2 = 4:1);
write.table(x, "tmp.txt", quote = FALSE, row.names = FALSE);
y <- read.table("tmp.txt", header= TRUE, row.names=1)
> y
X1 X2
10007787048271872 1 4
1007109516820319 2 3
10094843652996960 3 2
10145176274075488 4 1
> 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.
Thanks,
Markus
[[alternative HTML version deleted]]
______________________________________________
[email protected] 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.