[R] read.table problem with column headers

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Wed Mar 27 17:14:21 CET 2002


On Wed, 27 Mar 2002, Tom Arnold wrote:

> When I use read.table I can't get my column names to
> line up with my data.
>
> The data file has survey response data, and each line
> starts with a unique key field (which should be the
> row name when it gets read in, right? I've only been
> using R for one day so bear with me)
>
> The first row in the file has column names, and the
> first name is "Key", followed by "Age" and so on. for
> example:
>
> Key;Age;Gender;Years In IT; #more column labels...
> 20020220_144752_15178;41;0;17; #more data...
>
> When I read this in, saying
> survey = read.table("myfile.dat",TRUE,";")
>
> I wind up with "Age" column being named "Key" and all
> the column labels shift to the right. No matter what
> I've tried, I can't put *my* header on the first
> column of row names. If it put no header on that
> column, I get an error "more columns than column
> names"
>
> What can I do to get my data labels on correctly?

> read.table("myfile.dat",TRUE,";")
                    Key Age Gender Years.In.IT
1 20020220_144752_15178  41      0          17

is what I get from your code.  I suspect you wanted

> read.table("myfile.dat",TRUE,";", row.names=1)
                      Age Gender Years.In.IT
20020220_144752_15178  41      0          17

Do you perchance have the wrong number of names in your first line,
say one too few?


-- 
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list