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
+ }
I presume that the Vi is wrong, because in this syntax i is not known
as a variable. But I don´t know how to say that it is a variable here.
Would be nice if somebody could help me.
Perhaps I´m thinking too complicated and there is an easier way to do
this.
Thanks in advance
Greetings
Birgit
Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
birgit.lemcke@systbot.uzh.ch
[[alternative HTML version deleted]]
sapply(1:85, function(i) eval(parse(text=paste("range(V", i, ",
na.rm=T)", sep=""))))
Jacques VESLOT
INRA - Biostatistique & Processus Spatiaux
Site Agroparc 84914 Avignon Cedex 9, France
Tel: +33 (0) 4 32 72 21 58
Fax: +33 (0) 4 32 72 21 84
Birgit Lemcke a ?crit :> 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
> + }
>
> I presume that the Vi is wrong, because in this syntax i is not known
> as a variable. But I don?t know how to say that it is a variable here.
> Would be nice if somebody could help me.
> Perhaps I?m thinking too complicated and there is an easier way to do
> this.
>
> Thanks in advance
>
> Greetings
>
> Birgit
>
> 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]]
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help at 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
> and provide commented, minimal, self-contained, reproducible code.
>
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
+ }
Your V1 to V85 are probably coming from a data.frame, aren't they?
If yes, and if this data.frame is named 'a', you can use
'sapply(a,range)'
Otherwise, see ?get (get(paste("V","1",sep=""))
returns V1)
Christophe
On 6/28/07, Birgit Lemcke <birgit.lemcke@systbot.uzh.ch>
wrote:>
> 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
> + }
>
> I presume that the Vi is wrong, because in this syntax i is not known
> as a variable. But I don´t know how to say that it is a variable here.
> Would be nice if somebody could help me.
> Perhaps I´m thinking too complicated and there is an easier way to do
> this.
>
> Thanks in advance
>
> Greetings
>
> Birgit
>
> Birgit Lemcke
> Institut für Systematische Botanik
> Zollikerstrasse 107
> CH-8008 Zürich
> Switzerland
> Ph: +41 (0)44 634 8351
> birgit.lemcke@systbot.uzh.ch
>
>
>
>
>
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
Christophe Pallier (http://www.pallier.org)
[[alternative HTML version deleted]]
Birgit Lemcke wrote:> 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 > + } > > I presume that the Vi is wrong, because in this syntax i is not known > as a variable. But I don?t know how to say that it is a variable here. > Would be nice if somebody could help me. > Perhaps I?m thinking too complicated and there is an easier way to do > this. >Hi Birgit, This may be what you want: for(i in 1:85) print(do.call("range",list(as.name(paste("V",i,sep=""))))) Jim
Hello Patrick,
this does not work and gives following warning message:
for(i in 1:85) range(get(paste("V", i, sep="")), na.rm=TRUE)
Warning messages:
1: kein nicht-fehlendes Argument für min; gebe Inf zurück
2: kein nicht-fehlendes Argument für max; gebe -Inf zurück
This works but also with the warning message:
Vranges <- array(NA, c(85, 2))
for(i in 1:85) Vranges[i,] <- range(get(paste("V", i,
sep="")),
na.rm=TRUE)
Greetings
Birgit
Am 28.06.2007 um 12:27 schrieb Patrick Burns:
> In your code the 'range' call is only seen when i is 85.
> I think the following is what you want:
>
> for(i in 1:85) range(get(paste("V", i, sep="")),
na.rm=TRUE)
>
> Except that nothing is done with the results of 'range'. More
> likely is:
>
> Vranges <- array(NA, c(85, 2))
> for(i in 1:85) Vranges[i,] <- range(get(paste("V", i,
sep="")),
> na.rm=TRUE)
>
> See S Poetry for details.
>
> Patrick Burns
> patrick@burns-stat.com
> +44 (0)20 8525 0696
> http://www.burns-stat.com
> (home of S Poetry and "A Guide for the Unwilling S User")
>
> Birgit Lemcke wrote:
>
>> 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
>> + }
>>
>> I presume that the Vi is wrong, because in this syntax i is not
>> known as a variable. But I don´t know how to say that it is a
>> variable here.
>> Would be nice if somebody could help me.
>> Perhaps I´m thinking too complicated and there is an easier way to
>> do this.
>>
>> Thanks in advance
>>
>> Greetings
>>
>> Birgit
>>
>> Birgit Lemcke
>> Institut für Systematische Botanik
>> Zollikerstrasse 107
>> CH-8008 Zürich
>> Switzerland
>> Ph: +41 (0)44 634 8351
>> birgit.lemcke@systbot.uzh.ch
>>
>>
>>
>>
>>
>>
>> [[alternative HTML version deleted]]
>>
>>
>> ---------------------------------------------------------------------
>> ---
>>
>> ______________________________________________
>> 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
>> and provide commented, minimal, self-contained, reproducible code.
>>
Birgit Lemcke
Institut für Systematische Botanik
Zollikerstrasse 107
CH-8008 Zürich
Switzerland
Ph: +41 (0)44 634 8351
birgit.lemcke@systbot.uzh.ch
[[alternative HTML version deleted]]