[R] How to get rid of NULL in the result of apply()?

hadley wickham h.wickham at gmail.com
Fri Dec 11 06:17:03 CET 2009


> Is there a version of apply that returns a list without NULL's?
>
> I try to remove NULL elements in the following example, but neither
> for loops work. Would you please let me know what the correct way is?

Try this function:

compact <- function(x) Filter(Negate(is.null), x)
compact(x)

Hadley


-- 
http://had.co.nz/




More information about the R-help mailing list