[R] loop does not work

From: aude Valade <aude.valade_at_gmail.com>
Date: Mon, 28 Jul 2008 13:24:30 -0700


Hi,
I am new to R and am trying to do a loop but it seems not to run after one turn.
What I want to do is subset my dataframe (extract one station and one day) to calculate and store the maxima that can then be plotted. I have an error message at the end of each loop: Error: unexpected '}' in "}"

Here is my code:



datafile <-
read.csv(file="all_stations_24h_at_rh_0701-0718.csv",head=TRUE,sep=",")
#-------------build maxima vector----------------
maxima<-mat.or.vec(132,18)
Temp<-mat.or.vec(1,24)
regions<-levels(datafile$Region)
stations<-levels(factor(datafile$Stn.Id)) days<-levels(datafile$Date)

i=1
j=1

        while(i<length(stations)) {
            while (j<length(days) {
                print(j)
                print(days[j])
                #Temp <- as.numeric(levels(subset(datafile$Air.Temp...F.,
datafile$Stn.Id==stations[i] &

datafile$Date==days[j])))[subset(datafile$Air.Temp...F., datafile$Stn.Id==stations[i] & datafile$Date==days[j])]
                print(Temp)
                Temp <-

as.numeric(as.character(subset(datafile$Air.Temp...F., datafile$Stn.Id==stations[i] & datafile$Date==days[j])))
                maxima[[i,j]]<-max(Temp)
                j<-j+1
                }

            print(i)
            x11()
            print(stations[i])
            plot(maxima[i,], ylim=c(50,110), col="red")
            lines(maxima[i,])
            title(main=stations[i])
            i<-i+1
            }
**************************************

Thank you for your help.

Aude

        [[alternative HTML version deleted]]



R-help_at_r-project.org 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. Received on Mon 28 Jul 2008 - 20:27:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 28 Jul 2008 - 21:33:11 GMT.

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

list of date sections of archive