[R] Probelm with read.table
Martyn Plummer
plummer at iarc.fr
Thu Dec 11 12:54:44 CET 2003
On Thu, 2003-12-11 at 11:31, Arnaud_Amsellem at ssga.com wrote:
> Hi All,
>
> I have the following text file (mytextfile.txt)
>
> 738307 527178 714456 557955
> #N/A 17.42 6.22 4.73
> #N/A 17.3 6.23 4.75
> #N/A 17.29 6.17 4.7
> #N/A 17.07 6.12 4.6
> #N/A 17.27 6.19 4.7
> #N/A 17.72 6.4 4.78
> #N/A 17.12 6.19 4.75
> #N/A 17.07 6.15 4.65
> #N/A 17.03 6.07 4.64
> #N/A 17.38 6.13 4.7
> #N/A 17.38 6.13 4.7
> #N/A 17.38 6.13 4.7
> #N/A 17.38 6.13 4.7
> #N/A 17.34 6.28 4.7
> 10 17.57 6.33 4.75
> 11 17.57 6.33 4.75
> 12 17.57 6.33 4.75
> 13 17.39 6.25 4.87
> 14 17.15 6.33 5.06
> 15 17.05 6.21 5
> 16 16.87 6.14 5.15
> 17 16.72 6.27 5.23
>
> I use the following command:
> mydf <- read.table(file="mytextfile.txt", header = T, sep="\t",na.strings="
> #NA")
>
> When the above command is applied I have only 8 lines in mydf. I tried many
> options but nothing seems to get me the entire file. If the #NA are not in
> the first column it seems to work fine i.e I get 22 lines in mydf.
> Anyone would know a way of getting the entire file even if #NA are in the
> first column?
The character "#" is a comment character, so lines beginning in "#"
are ignored. To read these lines, set the parameter comment.char to
something else, e.g.
read.table("mytextfile.txt", header=TRUE, sep="\t", na.strings="#N/A",
comment.char="%")
Martyn
More information about the R-help
mailing list