Re: [R] read table

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Tue, 05 Jun 2007 18:56:21 +0100 (BST)

On Tue, 5 Jun 2007, Sarah Goslee wrote:

> The default separator in read.table is white space, so the first
> line (header) has 6 elements, the second line has 7 elements,
> and the third has 8 elements.
>
> Either delete the spaces in the car names, or use sep="\t"
> (or whatever is appropriate).

Or add quotes around character fields which contain spaces. By default either single or double quotes will work (used in matched pairs, of course).

>
> ?read.table explains this.
>
> Sarah
>
> On 6/5/07, jiqiang yao <jiqiang123_at_yahoo.com> wrote:
>> Hi,
>> I'm a novice of R.
>>
>> I want to read the following table into R:
>> names mpg cyl disp hp drat
>> Mazda RX4 21.0 6 160.0 110 3.90
>> Mazda RX4 Wag 21.0 6 160.0 110 3.90
>>
>> The command I used is:
>>> test <- read.table(file.choose(),header=T)
>>
>> The result is:
>> Error in read.table(file.choose(), header = T) :
>> more columns than column names
>>
>> Can anybody tells me what is wrong?
>>
>> ___________________
>
>
>

-- 
Brian D. Ripley,                  ripley_at_stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-help_at_stat.math.ethz.ch 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 Tue 05 Jun 2007 - 18:01:41 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 Tue 05 Jun 2007 - 18:32: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.