Re: [R] macro facility in R

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Tue 04 Jul 2006 - 02:32:19 EST

On Mon, 3 Jul 2006, John Sorkin wrote:
> R 2.2 on windows XP
> I have a dataset with multiple columns. Some of the columns represent
> independent variables, some represent dependent variables. I would like
> to run the same analyses on a fixed set of independent variables,
> changing only the dependent variable, e.g.
> y1-y2=x1+x2+x3
> y3-y4=x1+x2+x3
> y5-y6=x1+x2+x3, etc.

Other people have mentioned my defmacro() function in R-news, however when I have to do this sort of thing I usually use substitute or bquote

For example

for(i in 1+(1:5)*2){

   A<-as.name(paste("y",i,sep=""))
   B<-as.name(paste("y",i+1,sep="")
   eval(bquote(lm(I(.(A)-.(B))~x1+x2+x3,data=dat)))
}

         -thomas



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Tue Jul 04 02:36:27 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 04 Jul 2006 - 04:14:41 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.