Andreas Leha
2015-Jul-09 00:41 UTC
[R] why must a named colClasses in read.table be in correct order
Hi all,
Apparently, the colClasses argument to read.table needs to be in the
order of the columns *even when it is named*. Why is that? And where
would I find it in the documentation?
Here is a MWE:
--8<---------------cut here---------------start------------->8---
kkk <- c("a\tb",
"3.14\tx")
read.table(textConnection(kkk),
sep="\t",
header = TRUE)
cclasses=c(b="character",
a="numeric")
read.table(textConnection(kkk),
sep="\t",
header = TRUE,
colClasses = cclasses) ## <--- error
read.table(textConnection(kkk),
sep="\t",
header = TRUE,
colClasses = cclasses[order(names(cclasses))])
--8<---------------cut here---------------end--------------->8---
Thanks,
Andreas