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]]