[R] trouble with read.table and colClasses='raw'
Peter Ehlers
ehlers at ucalgary.ca
Thu Feb 11 19:36:58 CET 2010
Johan Jackson wrote:
> Hi Don and all,
>
> I guess we're getting somewhere. Thanks. The file (first three columns,
> first five rows) looks like this:
>
> X10 X20 X30
> 00 00 01
> 00 02 02
> 00 00 00
> 00 01 01
> 00 00 00
>
>
> I guess R is reading 00 as a character? But here's the weird thing: this
> data (a raw matrix in R) was written out by R itself:
>
> write.table(dat,"data",col.names=T,row.names=F,quote=F)
>
> *If* I understand correctly, then this seems like very *bad behavior* on R's
> part: you should be able to write out a matrix and read it right back into R
> without hassles like this (but everytime I blame R, it turns out to be user
> error, so...),
>
> JJ
Well, R is stupid, of course, so there's not much sense in
blaming R. You could blame the designers/programmers, but I
wouldn't do that - they seem like pretty smart people.
Still, I can sympathize. When I first got my Porsche, I
couldn't figure out how to make it go faster and why it
kept making so much noise. Then someone told me that the
left foot pedal wasn't just a footrest. And thus I discovered
that there are non-automatics in this world. -:)
Anyway, I just read your sample data into R, saved it with
your write() command and read it back with
dat <- read.table(file="data", header=TRUE, colClasses="character")
I suspect that you really don't know what 'raw' type means
and haven't bothered to check ?raw. It's also pretty clear
that you haven't read the colClasses description in
?read.table very carefully. The one thing R help pages are
pretty good at is careful definition of arguments.
I do hope that your day will improve.
-Peter Ehlers
[......]
--
Peter Ehlers
University of Calgary
More information about the R-help
mailing list