Skip to content
Prev 23399 / 29559 Next

Conditional operations and rasters

Hi all,

This is probably a silly question, but I could not find an appropriate answer somewhere else.

I am trying create a raster based on conditional statements applied on an original raster.

This is some sample code:

lai <- raster(ncols=360, nrows=180)
lai[] <- 1:ncell(lai)

if (lai < 1000) {

    emiss_0  <- 0.95 + (0.01 * lai)
    emiss_nb <- 0.97 + (0.0033 * lai)


} else if (lai >= 1000) {


    emiss_0  <- 0.95
    emiss_nb <- 0.98


}

Error in if (lai < 3) { : argument is not interpretable as logical


What would be the right way to do that? 
 Greetings,
 -- Thiago V. dos Santos

PhD student
Land and Atmospheric Science
University of Minnesota