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 at web.de>
To: r-help at 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 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
Petr Pikal
petr.pikal at precheza.cz