Re: [R] Building a formula using paste

From: john seers \(IFR\) <john.seers_at_bbsrc.ac.uk>
Date: Fri, 1 Feb 2008 12:06:35 -0000

 

Thank you very much. That problem has been niggling me for some time.

I slotted in your code and it worked. I just need to spend a bit of time understanding it ...

Thanks again.

John Seers  

---

-----Original Message-----
From: Bill.Venables_at_csiro.au [mailto:Bill.Venables_at_csiro.au] 
Sent: 01 February 2008 09:57
To: Bill.Venables_at_csiro.au; john seers (IFR); r-help_at_stat.math.ethz.ch
Subject: RE: [R] Building a formula using paste

Please disregard my previous reply.  Now that I have read your question,
all becomes clear.

To do what you want to do is a bit tricky.  Here is one way

f1 <- as.name("F1")
fm <- eval(bquote(aov(.(f1) ~ sensoryTerm, data = vdata)))

Them fm is the fitted model object, suitably formed.

E&OE, of course! 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely
necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables_at_csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
On Behalf Of Venables, Bill (CMIS, Cleveland)
Sent: Friday, 1 February 2008 7:45 PM
To: john.seers_at_bbsrc.ac.uk; r-help_at_stat.math.ethz.ch
Subject: Re: [R] Building a formula using paste

use as.formula() rather than just formula(). 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251 Fax (if absolutely
necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables_at_csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces_at_r-project.org [mailto:r-help-bounces_at_r-project.org]
On Behalf Of john seers (IFR)
Sent: Friday, 1 February 2008 7:31 PM
To: r-help_at_stat.math.ethz.ch
Subject: [R] Building a formula using paste


Hi All

I have looked but cannot find an answer to this.

I want to build a formula dynamically (in a function), using for example
paste, and using it in a model:

	fr<-"F1"	
  	f1<-formula(paste(fr, "~ SensoryTerm"))
  	m1<-aov(f1, data=vdata)

So this is the equivalent of m1<-aov(F1 ~ SensoryTerm, data=vdata)

This works fine but the problem is the formula appears as "f1" in the
summary(m1) of the model and not "F1 ~ SensoryTerm". With many models
this can be a bit confusing ....

Is there a way to code this so the formula appears in the model summary?

Regards


John Seers





> sessionInfo()
R version 2.6.1 (2007-11-26) i386-pc-mingw32 locale: LC_COLLATE=English_United Kingdom.1252;LC_CTYPE=English_United Kingdom.1252;LC_MONETARY=English_United Kingdom.1252;LC_NUMERIC=C;LC_TIME=English_United Kingdom.1252 attached base packages: [1] stats graphics grDevices datasets utils methods base other attached packages: [1] pixmap_0.4-7 gplots_2.3.2 gdata_2.3.1 gtools_2.4.0 rcom_1.5-2.2 [6] nnet_7.2-38 e1071_1.5-17 class_7.2-38 tree_1.0-26 mgcv_1.3-29 [11] MASS_7.2-38 car_1.2-7 RODBC_1.2-2 RWinEdt_1.7-9
>
--- ______________________________________________ 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. ______________________________________________ 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.
Received on Fri 01 Feb 2008 - 12:13:18 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 Fri 01 Feb 2008 - 13:30:10 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.

list of date sections of archive