Error in x[[i]] : recursive indexing failed at level 2

x<-list(1:5,NULL)

lapply(x, function(el) {
    if(is.null(el)) el else {
        ifelse(el %in% 1, 25, el)
    }
    })

#[[1]]
#[1] 25  2  3  4  5

#[[2]]
#NULL

use lapply to work with and return lists. It’s better to use %in% because == will fail on missing values.

Leave a Comment

tech