[R] problem with read.table

Nordlund, Dan (DSHS/RDA) NordlDJ at dshs.wa.gov
Thu Apr 16 00:28:26 CEST 2009


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of x
> Sent: Wednesday, April 15, 2009 2:43 PM
> To: r-help at r-project.org
> Subject: Re: [R] problem with read.table
> 
> 
> I forgot to show that my file indeed contains x, y values:
> 
> x	y
> 1	8.2
> 2	18
> 3	-17.6
> 4	-3.4
> 5	6.8
> 6	11.3
> 7	1.5
> 8	11
> 9	-3.3
> 10	8.1
> 
> 
> --- On Wed, 4/15/09, x <to_rent_2000 at yahoo.com> wrote:
> 
> > From: x <to_rent_2000 at yahoo.com>
> > Subject: RE: [R] problem with read.table
> > To: r-help at r-project.org, "Nordlund, Dan (DSHS/RDA)"
> <NordlDJ at dshs.wa.gov>
> > Date: Wednesday, April 15, 2009, 5:09 PM
> > Thank you for the reply. That format works but since I need
> > access to x, y subsequent to lm() also, I tried the
> > following but now I'm back to the same old error message
> > of "object y not being found".
> >
> > data_model.df = read.table("./verify.txt",
> > header=TRUE, nrows=10);
> > dd = datadist(data_model.df);
> > options(datadist = 'dd');
> > describe(data_model.df);
> >
> > f <- lm(y ~ x)
> > print( summary(f) )
> >
> > plot(x, y)
> >
> > I tried without "options" and
> > "describe" and still the same problem.
> >
> > Thanks again!
> >

After 

    data_model.df = read.table("./verify.txt", header=TRUE, nrows=10)

you can attach the dataframe and refer to the individual variables in the dataframe by name

    attach(data_model.df)

or you can refer to the variables as

    data_model.df$x
    data_model.df$y 

or

    data_model.df[1]
    data_model.df[2]

You might want to read the "Introduction to R" manual, in particular, section 6.

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA  98504-5204
 




More information about the R-help mailing list