[R] double if else

Daisy Englert Duursma daisy.duursma at gmail.com
Mon Feb 23 03:54:32 CET 2015


Hello,
I need to make a double clause in an if else/ next statement. I wrote a
single one fine but I could not make it work for two statements statements.

Please see the following example:


#Goals
  #1)if size of area is greater than 15000 test that there are a minimum of
nrow() = 30,
    #write those with at least 30 values to list
  #2) if less than 15000, write those with >= 5 rows

# in the following example I should have a list where one has a value of 10
and the other 20.


areaKM <- 7500 #test for 7500 and 30000, at 30000 should have empty list
dat<-data.frame(x=1:30,y=31:60,cellvalue=c(5,6,7,rep(10,10),rep(20,17)))#fake
data
cells<-unique(as.numeric(dat$cellvalue))#find unique cellvalues
pres100km <- list() #empty list

#make loop to find dat$cellsvalue with at least 30 rows or if areaKM is
less than15000  keep cellvalues for those with more than 5 rows.
for (ii in 1:length(cells)){
  subdat<-subset(dat,cellvalue ==cells[ii])
  if (areaKM >- 15000) {
    if (nrow(subdat) < 30) {
      next
    } else {
      pres100km[[ii]]<-cells[ii] #100kmcells >= 30% coverage of 10kmcells
    }
  } else {
    if (nrow(subddat) < 5) {
      next
    } else {
      pres100km[[ii]]<-cells[ii] #100kmcells >= 50% coverage of 10kmcells
    }
  }
}







-- 
Daisy Englert Duursma
Department of Biological Sciences
Room W19F 135
Macquarie University, North Ryde, NSW 2109
Australia

Tel +61 2 9850 1302

	[[alternative HTML version deleted]]



More information about the R-help mailing list