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

From: Juliet Hannah <juliet.hannah_at_gmail.com>
Date: Thu, 03 Jul 2008 10:40:28 -0400


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!



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 - 14:43:43 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