Re: [R] Read.table - Less rows than original data

From: Philipp Pagel <p.pagel_at_wzw.tum.de>
Date: Wed, 09 Jul 2008 22:39:08 +0200

> I built a 1,273,230 by 6 data set named "mydata2", it was saved in the
> following command,
>
> write.table(mydata2, "mydata2.txt", row.name=F,col.name=T,quote=F,sep="\t")
>
> The next day I read in above saved text file into R,
>
> temp<-read.table("mydata2.txt",header=T,sep="\t",na.strings="NA")
>
> However, the dimension of "temp" is 636,615 X 6.

A wild guess: does your table contain strings which include single or double ticks? As you are not disabling quoting in read.table this can cause problems:

> foo = data.frame(a=c("abc","5'foo","xxx", "3'bar"), b=1:4)
> foo

      a b
1 abc 1
2 5'foo 2
3 xxx 3
4 3'bar 4

> write.table(foo, "mydata2.txt", row.name=F,col.name=T,quote=F,sep="\t")
> foo <- read.table("mydata2.txt",header=T,sep="\t",na.strings="NA")
> foo

                      a b
1                   abc 1

2 5foo\t2\nxxx\t3\n3bar 4

> foo <- read.table("mydata2.txt",header=T,sep="\t",na.strings="NA", quote='')
> foo

      a b
1 abc 1
2 5'foo 2
3 xxx 3
4 3'bar 4

The same aplies to comment characters embedded in strings.

If this is not your problem, I'd first check if the file has the expected number of lines.

cu

        Philipp

-- 
Dr. Philipp Pagel
Lehrstuhl für Genomorientierte Bioinformatik
Technische Universität München
Wissenschaftszentrum Weihenstephan
85350 Freising, Germany
http://mips.gsf.de/staff/pagel

______________________________________________
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 Wed 09 Jul 2008 - 20:55:24 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 Wed 09 Jul 2008 - 21:32:08 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