Hello, I have difficulties in reading in a text file with multiple (=2) header lines. My table looks like this: id code gr grcode AA AB AC AD time 30 40 50 60 1 1234 1 c 0 1 0 0 2 1346 1 c 0 0 0 1 3 1456 1 c 0 0 1 1 4 1893 1 c 0 0 1 1 Can someone help me out? Thanks Deborah --
On Mon, Apr 07, 2008 at 07:47:41PM +0200, Deborah Kronenberg wrote:> > I have difficulties in reading in a text file with multiple (=2) header lines. > My table looks like this: > > id code gr grcode AA AB AC AD > time 30 40 50 60 > 1 1234 1 c 0 1 0 0 > 2 1346 1 c 0 0 0 1 > 3 1456 1 c 0 0 1 1 > 4 1893 1 c 0 0 1 1 > > Can someone help me out?Hm - depends on what exactly you would like to do with the second row. If all you want is discard it you may try: foo = read.table('foo.tbl', skip=2) hl = readLines('foo.tbl', 1) hl = strsplit(hl, '\t') colnames(foo) = hl[[1]] If the second line is important to distinguish between column labels in the first row, something along these lines could be what you want: foo = read.table('foo.tbl', skip=2) hl = readLines('foo.tbl', 2) hl = strsplit(hl, '\t') colnames(foo) = sub('_$', '', paste(hl[[1]], hl[[2]], sep="_")) cu Philipp -- Dr. Philipp Pagel Tel. +49-8161-71 2131 Lehrstuhl f?r Genomorientierte Bioinformatik Fax. +49-8161-71 2186 Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany and Institut f?r Bioinformatik und Systembiologie / MIPS Helmholtz Zentrum M?nchen - Deutsches Forschungszentrum f?r Gesundheit und Umwelt Ingolst?dter Landstrasse 1 85764 Neuherberg, Germany http://mips.gsf.de/staff/pagel
If there are no t's in your file other than in the second line then:
read.table("myfile.dat", comment = "t", header = TRUE)
On Mon, Apr 7, 2008 at 1:47 PM, Deborah Kronenberg
<Deborah.kronenberg at gmx.de> wrote:> Hello,
>
> I have difficulties in reading in a text file with multiple (=2) header
lines. My table looks like this:
>
> id code gr grcode AA AB AC AD
> time 30 40 50 60
> 1 1234 1 c 0 1 0 0
> 2 1346 1 c 0 0 0 1
> 3 1456 1 c 0 0 1 1
> 4 1893 1 c 0 0 1 1
>
> Can someone help me out?
>
> Thanks
>
> Deborah
> --
>
> ______________________________________________
> 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.
>