Re: [R] read.table, NA assignment, and sep

From: Peter Dalgaard <P.Dalgaard_at_biostat.ku.dk>
Date: Thu, 03 Jul 2008 17:40:41 +0200

Juliet Hannah wrote:
> I place the following data in a file
>
> id rs835 rs169 rs174
> 1001 CC GG CC
> 10032 CC GG CC
> 10066 CC NA CC
>
> If I read it in as
> tempDat <- read.table("tempDat.txt",na.strings="NA",header=TRUE)
>
> I get the following.
>
> id rs835 rs169 rs174
> 1 1001 CC GG CC
> 2 10032 CC GG CC
> 3 10066 CC <NA> CC
>
> NA has been assigned a missing value.
>
> If I add the separator
>
> tempDat <- read.table("tempDat.txt",na.strings="NA",sep="\t",header=TRUE)
> tempDat
> id rs835 rs169 rs174
> 1 1001 CC GG CC
> 2 10032 CC GG CC
> 3 10066 CC NA CC
>
> NA does not get assigned a missing value.
>
> Could you help me understand the logic of this. Thanks!
>
This kind of thing doesn't travel well in email, but is is possible that there is more than "\t" between fields?

levels(tempDat$rs169) could be illuminating.

-- 
   O__  ---- Peter Dalgaard             Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard_at_biostat.ku.dk)              FAX: (+45) 35327907

______________________________________________
R-help_at_r-project.org 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.
Received on Thu 03 Jul 2008 - 15:45:08 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 03 Jul 2008 - 16:31:02 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive