Re: [R] nested for loop restriction?

From: Petr Pikal <petr.pikal_at_precheza.cz>
Date: Tue 20 Jun 2006 - 22:56:03 EST


Hi

If you do not insist on loops you can either use merge

merge(tpframe, pqframe)

or

df.new<-data.frame(date=tpframe$date,
discharge=pqframe$discharge[match(tpframe$gage heights, pqframe$gage heights)])

I hope I did not do typo :-)

HTH
Petr

On 20 Jun 2006 at 14:20, René Capell wrote:

Date sent:      	Tue, 20 Jun 2006 14:20:50 +0200
From:           	René Capell <rene.ca@web.de>
To:             	r-help@stat.math.ethz.ch
Organization:   	http://freemail.web.de/
Subject:        	[R] nested for loop restriction?

> Hello,
>
> is there a restriction for the number of loops in a nested for-loop in
> R? I wrote a small function to replace water gage hights by discharge
> values, where the outer loop walks through the levels of a gage time
> series and the inner loop looks up the corresponding dicharge value in
> a vector. It seems to work well, with the (however very annoying)
> restriction that the inner loop stops after 60 steps. I attached the
> function at the end of the mail, where tpframe is a 2-column time
> series dataframe (date,gage hights) and pqframe is a 2-column
> dataframe (gage hights, discharge). Any kind of help appreciated, as
> I am no native programmer and also quite new to R also replies like
> "nice try, but there is a more convenient way in R: ...",
>
> thanks in advance,
> René
>
>
> p.zu.q <- function (tpframe, pqframe) {
> tp <- factor(tpframe[[2]])
> tq <- tp
> p <- pqframe[[1]]
> q <- pqframe[[2]]
>
> for (i in 1:length(levels(tp))) {
> pegel<-levels(tp)[i]
>
> for (j in 1:length(brugga.p)) {
> if (p[j] == pegel)
> {levels(tq)[i] <- q[j]
> break
> }
> else next
> }
> next
> }
>
> tpq <- cbind(tpframe[[1]],as.data.frame(tp),as.data.frame(tq))
> names(tpq) <- c("date","P mm","Q m3/s")
> tpq
> }
> _____________________________________________________________________
> Der WEB.DE SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
>
> ______________________________________________
> 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 Tue Jun 20 23:00:01 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 21 Jun 2006 - 00:12:16 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.