[R] equivalent of Stata "by construct"

Daniel Nordlund djnordlund at frontier.com
Thu Sep 27 20:18:18 CEST 2012


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
> On Behalf Of Pradipto Banerjee
> Sent: Thursday, September 27, 2012 9:13 AM
> To: r-help at r-project.org
> Subject: [R] equivalent of Stata "by construct"
> 
> I am evaluating a switch from Stata to R. I don't need to extensive
> Statistical methods, but the main reason I am exploring the switch is the
> coding flexibility in R (e.g. Stata does not support linear/quadratic
> programming). I have been going over the R syntax and I had a quick
> question:
> 
> In Stata, one has a very useful construction called "by", e.g.
> 
> by month signal: gen xxx = myfunction(yyy zzz) if cond1==cond2
> 
> Similarly, in SAS, one can write
> 
> by monthn signal;
> if cond1=cond2 then xxx = myfunction(yyy zzz);
> run;
> 
> 
> I looked at a lot of R tutorials, but I haven't come across the equivalent
> of the Stata or SAS "by" construct in R?
> 
> 
> 

Check out the function by() in base R.

Dan

Daniel Nordlund
Bothell, WA USA




More information about the R-help mailing list