Wincent wrote:
Dear all, I have a list like this: l <- list(list(a=1,b=NULL), list(a=2,b=2)) I want to find out the elements with value of NULL and replace them with NA. The actual case has a very long list, so manually find out and replace them is not an option. I can use for loop to do this, but I want to know if there is vectorized way (or other ways) to do it?
Note: You have provided a list *of lists*. Is that what you actually have? If so, Solution 1: Change whatever is generating the NULL values to NA in the first place Solution 2: lapply(l, function(x) lapply(x, function(x) ifelse(is.null(x), NA, x))) ______________________________________________ R-help@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.