[R] Newbie query - reading data into R

Prof Brian Ripley ripley at stats.ox.ac.uk
Tue Jan 26 13:02:49 CET 1999



Try sep="\t", if they are really separated by tabs (they were not in
your email by the time it reached here).  Actually, you don't need
as.if=F, either, as the first column should be the row names:

> read.table("test.dat", header=T, row.names=1, sep="\t")
             Number
Napier          324
Auckland        657
Wellington      879
Christchurch    904

works on your example (with tabs in the file).

(S-PLUS behaves differently here, and guesses the first column
should be the row names without being told).  

I don't know how you got a list -- that may depend on the version of
R you used, so please tell us when you post. (On 0.63.2 I tried
a few ideas, but failed.  It may be that you do in fact have
a data frame, but a malformed one so that it prints like a list.)


> Date: Tue, 26 Jan 1999 22:30:09 +1300
> From: Andy Elvey <andyelv at ibm.net>
> 
> ( This may seem a basic query, but anyway ... here goes ... :-)  
> 
> I have a simple ASCII dataset which I'm trying to read into R (and
> trying to get R  to accept it as a data-frame).  The data is of the form
> - 
> 
>  City           Number
>  Napier         324
>  Auckland       657
>  Wellington     879
>  Christchurch   904
>   
>   - and so on.   The data is separated by tabs , as above.  
> 
>  I use the read.table function as follows - 
> 
>   a <- read.table("C:\\RNew\\Doc\\data1.txt",as.is=F,header=T) 
> 
>  This reads the data in OK, but it is as a list - not as a data-frame.
> How can I use the read.table function to read the data into a
> data-frame? 
> 
>  I have documentation for S-plus and have read the R documentation, but
> so far -  no success. 

Beware, R is `not unlike S' but it is also different from S-PLUS,
in ways that change by the R version.

-- 
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