Skip to content
Prev 30558 / 398513 Next

removing NULL elements from a list

somelist[!sapply(somelist, is.null)]

e.g.
$a
[1] 1

$c
[1] 3

$e
[1] 5

It you want to confuse people, try s[sapply(s, is.null)] <- NULL
which also removes the NULL components.
On Mon, 14 Apr 2003, Ramon Diaz wrote: