Re: [R] read.table mystery

From: David Winsemius <dwinsemius_at_comcast.net>
Date: Sun, 06 Mar 2011 12:43:45 -0500

On Mar 6, 2011, at 10:19 AM, Sarah Goslee wrote:

> Not so much a mystery. read.table() only looks at the first 5 lines
> when
> decided how many columns your file has (as described in the Details
> section of the help).
>
> The easiest solution is to add a col.names argument to read.table()
> with
> the correct number of names.
>
> You may want to also include as.is=TRUE if you don't want your data to
> be imported as factors. If you expect character but have factor you
> may
> get unexpected results later.

There is also a fill argument for read.table that may be needed when the length of colClasses or col.names exceeds the length of some rows.

-- 
David.

>
> Sarah
>
> On Sun, Mar 6, 2011 at 5:04 AM, Johannes Graumann
> <johannes_graumann_at_web.de> wrote:
>> Hello,
>>
>> Please have a look at the code below, which I use to read in the
>> attached
>> file. As line 18 of the file reads "1065:>sp|Q9V3T9|ADRO_DROME
>> NADPH:adrenodoxin oxidoreductase, mitochondrial OS=Drosophila
>> melanogaster
>> GN=dare PE=2 SV=1", I expect the code below to produce a 3 column
>> data frame
>> with most of the last column empty and line 18 to produce a
>> data.frame row
>> like so:
>>
>> V1
>> 1065
>> V2
>>> sp|Q9V3T9|ADRO_DROME NADPH
>> V3
>> adrenodoxin oxidoreductase, mitochondrial OS=Drosophila
>> melanogaster GN=dare PE=2 SV=1
>>
>> Why is that not so?
>>
>> Thanks for any hint.
>>
>> Sincerely, Joh
>>
>> read.table(
>> "/tmp/testfile.txt",
>> sep=":",
>> header=FALSE,
>> quote="",
>> fill=TRUE
>> )[19,]
>
> ---
> Sarah Goslee
> http://www.functionaldiversity.org
>
> ______________________________________________
> 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.
David Winsemius, MD Heritage Laboratories West Hartford, CT ______________________________________________ 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 Sun 06 Mar 2011 - 17:46:45 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 Sun 06 Mar 2011 - 17:50:18 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