[R] R is not reading(?) my data properly

Duncan Murdoch murdoch at stats.uwo.ca
Sat Feb 9 18:35:14 CET 2008


On 09/02/2008 11:37 AM, ONKELINX, Thierry wrote:
> Alexander,
> 
> Learn to use the data argument. E.g. 
> 
> plot(rgnpc, incmean, data = pol572a1)

That won't work.  The data arg to plot (and most other functions that 
have one) requires a formula, not a simple specification of x and y. 
You'd need

plot(incmean ~ rgnpc, data = po1572a1)

(The reason for this limitation is that plot needs to evaluate its first 
argument to know what method to call.  It can evaluate the formula 
"incmean ~ rgnpc", but can't evaluate the nonexistent "rgnpc".

Duncan Murdoch


> Model <- lm(incmean ~ rgnpc, data = pol572a1)
> 
> to get the fitted values:
> 
> Model$fitted
> 
> HTH,
> 
> Thierry
> 
> PS It seems to me that you might want to read a good introduction into
> R.
> 
> ------------------------------------------------------------------------
> ----
> ir. Thierry Onkelinx
> Instituut voor natuur- en bosonderzoek / Research Institute for Nature
> and Forest
> Cel biometrie, methodologie en kwaliteitszorg / Section biometrics,
> methodology and quality assurance
> Gaverstraat 4
> 9500 Geraardsbergen
> Belgium 
> tel. + 32 54/436 185
> Thierry.Onkelinx at inbo.be 
> www.inbo.be 
> 
> Do not put your faith in what statistics say until you have carefully
> considered what they do not say.  ~William W. Watt
> A statistical analysis, properly conducted, is a delicate dissection of
> uncertainties, a surgery of suppositions. ~M.J.Moroney
> 
> -----Oorspronkelijk bericht-----
> Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> Namens Alexander Ovodenko
> Verzonden: zaterdag 9 februari 2008 17:23
> Aan: r-help at r-project.org
> Onderwerp: [R] R is not reading(?) my data properly
> 
>  Thanks for the replies to my prior question.  My problem is that R
> always
> says object not found when I enter a variable name into a command.  I
> converted a Stata file into an Rdata file by first loading the foreign
> package by entering
> 
> require(foreign)
> 
> Then I asked R to read the Stata file by entering
> 
> pol572a1<- read.dta("C:\\alex\\Graduate Coursework\\Pol
> 572\\pol572a1.dta")
> 
> So now I can do a few things with the data, but I am only able to do so
> by
> entering
> 
> with(pol572a1,
> 
> before typing another command. So I enter the following for a scatter
> plot:
> with(pol572a1, plot(rgnpc, incmean))
> 
> When I run a simple linear regression, I enter the following:
> with(pol572a1,
> lm(incmean~rgnpc))
> 
> But when try to get a fitted line, I enter the following: with(pol572a1,
> lm(
> share.gnp)<-lm(incmean~rgnpc))  But I get the following error message:
> Error
> in lm(share.gnp) <- lm(incmean ~ rgnpc) : object "share.gnp" not found
> 
> So what should I do to get R to read the dataframe in the ordinary way
> with
> the usual command?  I am willing to scrap this dataframe and use the
> original Stata file to start over, as long as that resolves the problem.
> 
> Thanks!
> 
> Alex
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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.
> 
> ______________________________________________
> 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.



More information about the R-help mailing list