Message-ID: <200304151025.55743.rdiaz@cnio.es>
Date: 2003-04-15T08:25:55Z
From: Ramon Diaz-Uriarte
Subject: removing NULL elements from a list: Thanks
In-Reply-To: <x2el452i16.fsf@biostat.ku.dk>
Thank you very much for the very helpful responses from D. Bates, P. Dalgaard,
J. Holtman, D. James, U. Ligges, V. Ogranovich, C. Ortega, B. D. Ripley and
T. Plate.
The original question is at the end.
Most of the answers were: (A is the list, with the NULLs I want to get rid of)
A[!sapply(A, is.null)]
A[!unlist(lapply(A, is.null))]
A[sapply(A, is.null)] <- NULL ## potentially confussing, as pointed out by
B.D. Ripley
Thanks again,
Ram?n
> Dear All,
>
> I have a list, where several components are NULL, and I'd like to obtain
> that very same list without the NULL components (i.e., I do not want to
> unlist or otherwise loose the rest of the list structure). I can do that
> with a loop, but how could I do it without a loop?
--
Ram?n D?az-Uriarte
Bioinformatics Unit
Centro Nacional de Investigaciones Oncol?gicas (CNIO)
(Spanish National Cancer Center)
Melchor Fern?ndez Almagro, 3
28029 Madrid (Spain)
Fax: +-34-91-224-6972
Phone: +-34-91-224-6900
http://bioinfo.cnio.es/~rdiaz