On 03/28/2014 05:27 PM, Luana Marotta wrote:
Hi all,

I'm trying to find out what is the equivalent in R for the following Stata
code:

Let's say I have the variables: a1, a2, a3, a4, a5

forvalues i = 1(1)5 {
     summary a`i'
}

That is, I want to know how to loop through variables in R.

Hi Luana,
Try this:

for(var in paste("a",1:5,sep="")) print(summary(get(var)))

Jim

______________________________________________
R-help@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.

Reply via email to