[R] Loop problem

From: Jamie Ledingham <jamie.ledingham_at_newcastle.ac.uk>
Date: Wed, 26 Mar 2008 15:32:11 +0000


Dear all, I have a problem with a loop, if anyone has any knowledge on these things I would appreciate some comments. The code below is designed to allow me to extract the top record of the data frame, and them remove rows from the data frame which have an index close to the extracted top record.

topstorm<-subset(rankeddataset[1,]) ## Extracts the top storm topstormindex<-rankeddataset[1,1] ## Finds the top storm start index startindex<-topstormindex-48 ## sets the start and end indexes endindex<-topstorminde+48
rankeddataset<-rankeddataset[-1,] ## Creates a new list with the top storm removed

##This section of code needs looped. It removes storms from the list which are too close to the extracted storm

for (i in 1:30){
if (rankeddataset[i,1]>startindex && rankeddataset[i,1]<endindex) {rankeddataset<-rankeddataset[-i,]}
}

Here is some example data:

   82856  15 / 6 / 1966   82856:82879            25.9
   82857  15 / 6 / 1966   82857:82880            20.5
   83036  23 / 6 / 1966   83036:83059            17.3
   87250 15 / 12 / 1966   87250:87273            15.9

The loop does not currently work, it seems to remove every second line or so. Can anyone suggest why this might be, I'm not particularly experienced in using loops so it may be a rookie mistake. Thanks in advance.
Jamie Ledingham



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 Wed 26 Mar 2008 - 15:36:08 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 Thu 27 Mar 2008 - 14:30:24 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