[R] Repeat if
john seers (IFR)
john.seers at bbsrc.ac.uk
Thu Jun 28 16:49:39 CEST 2007
Hi Birgit
No, you do not have to write all 85 vectors in the first line. I just did not fully appreciate what you were trying to do.
You could use the "get" option as was suggested somewhere else.
So, if your vectors are V1 to V2 (i.e. 85) say, something like:
V1<-c(1,2,3)
V2<-c(5,2,7)
...
V<-paste("V", 1:2, sep="")
for ( i in 1:length(V) ) {
print(range (get(V[i]), na.rm = TRUE))
}
Regards
JS
---
Web sites:
www.ifr.ac.uk
www.foodandhealthnetwork.com
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Birgit Lemcke
Sent: 28 June 2007 15:12
To: john seers (IFR)
Cc: R Hilfe
Subject: Re: [R] Repeat if
Hello John,
I tried this code. But I got only the ranges of V1 and V2 what is easily understandable.
Do I have to write in all 85 vectors in the first line?
V<-list(a=c(V1), b=c(V2))
for ( i in 1:85 ) { # 2 vectors (replace with 85 ...)
+ print(range (V[i], na.rm = TRUE))
+ }
sapply(1:85, function(i) eval(parse(text=paste("range(V", i, ", na.rm=T)", sep=""))))
But thanks anyway.
Greetings
Birgit
Am 28.06.2007 um 12:23 schrieb john seers ((IFR)):
>
> Hi
>
> I think a for loop would be more what you want.
>
> Something along the lines of:
>
>
> V<-list(a=c(1,2,3), b=c(2,3,4)) # list of 2 vectors
>
> for ( i in 1:2 ) { # 2 vectors (replace with 85 ...)
> print(range (V[i], na.rm = TRUE))
> }
>
>
> Regards
>
> JS
>
> ---
>
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Birgit Lemcke
> Sent: 28 June 2007 10:48
> To: R Hilfe
> Subject: [R] Repeat if
>
> Hello,
> (Power Book G4, Mac OS X, R 2.5.0)
>
> I would like to repeat the function range for 85 Vectors (V1-V85).
> I tried with this code:
>
> i<-0
>> repeat {
> + i<-i+1
> + if (i<85) next
> + range (Vi, na.rm = TRUE)
> + if (i==85) break
> + }
Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
birgit.lemcke at systbot.uzh.ch
[[alternative HTML version deleted]]
More information about the R-help
mailing list