Re: [R] for-loop with multiple variables changing

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Mon 06 Feb 2006 - 22:42:49 EST


Hi

do you want this?

for(i in a) {print(a[i]); print(b[i])}

HTH
Petr

On 6 Feb 2006 at 11:53, Piet van Remortel wrote:

To:             	r-help@stat.math.ethz.ch
From:           	Piet van Remortel <piet.vanremortel@gmail.com>
Date sent:      	Mon, 6 Feb 2006 11:53:33 +0100
Subject:        	[R] for-loop with multiple variables changing

> Hi all,
>
> Never really managed to build a for-loop with multiple running
> variables in an elegant way.
>
> Can anybody hint ?
>
> See below for an example of what I would like.
>
> EXAMPLE
> a<-c(1,2,3)
> b<-c("name1","name2","name3")
>
> for( number in a, name in b ) {
> print( number ) ##take a value
> print( name ) ##and have its name available from a second list
> }
>
> Does R support this natively ?
>
> thanks !
>
> Piet
> (Univ. of Antwerp - Belgium)
>
> ______________________________________________
> 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

Petr Pikal
petr.pikal@precheza.cz



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 Mon Feb 06 22:59:15 2006

This archive was generated by hypermail 2.1.8 : Tue 07 Feb 2006 - 00:55:56 EST