[R] how to delete the null elements in list
Ben Bolker
bbolker at gmail.com
Fri Jan 25 14:16:30 CET 2013
Tammy Ma <metal_licaling <at> live.com> writes:
> > suu
> [[1]]
> NULL
> [[2]]
> NULL
> [[3]]
> item_id prod
> 1 2
> [[4]]
> item_id prod
> 1 2
> 2 4
>
> how to delete all "NULL" elements from suu to get only
>
> >suu
> [[3]]
> item_id prod
> 1 2
> [[4]]
> item_id prod
> 1 2
> 2 4
How about suu[!sapply(suu,is.null)] ? (Haven't tested, but I would
expect it to work ...
Of course, the result won't have elements [[3]] and [[4]],
it will have elements [[1]] and [[2]] ...
Ben Bolker
More information about the R-help
mailing list