From ggrothendieck at gmail.com  Wed May  9 17:40:57 2007
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Wed, 9 May 2007 11:40:57 -0400
Subject: [Rd] Behaviour of read.table with empty columns
In-Reply-To: <20070509151030.BAGH1673.tomts16-srv.bellnexxia.net@JohnDesktop8300>
References: <20070509151030.BAGH1673.tomts16-srv.bellnexxia.net@JohnDesktop8300>
Message-ID: <971536df0705090840u2eb24d33t5f535b4dfe6ac648@mail.gmail.com>

Perhaps this has to do with the fact that there is not enough
information available
to establish the class of those columns.  For example, try this:

read.table("clipboard", colClasses = "character")


On 5/9/07, John Fox <jfox at mcmaster.ca> wrote:
> Dear r-devel list members,
>
> I stumbled across the following behaviour of read.table() recently: Suppose
> that I have the data
>
> a  " " ""
> "" ""  ""
>
> in a file or copied to the clipboard, and issue the command
>
> > DF <- read.table("clipboard")
> > DF
>  V1 V2 V3
> 1  a NA NA
> 2    NA NA
>
> > is.na(DF)
>        V1   V2   V3
> [1,] FALSE TRUE TRUE
> [2,] FALSE TRUE TRUE
>
> I was surprised by the NAs. Note that they occur only when a column consists
> entirely of empty strings or strings composed of blanks.
>
> On the other hand
>
> > data.frame(A=c("", "", ""))
>  A
> 1
> 2
> 3
>
> works as I would have expected.
>
> A work-around for me was
>
> > DF[is.na(DF)] <- ""
> > DF
>  V1 V2 V3
> 1  a
> 2
>
> But, as I said, I found the behaviour of read.table() puzzling.
>
> All this is with R 2.5.0 on a Windows XP Pro SP 2 system.
>
> Comments?
>
> Thanks,
>  John
>
> --------------------------------
> John Fox, Professor
> Department of Sociology
> McMaster University
> Hamilton, Ontario
> Canada L8S 4M4
> 905-525-9140x23604
> http://socserv.mcmaster.ca/jfox
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] Behaviour of read.table with empty columns
Gabor Grothendieck