[R] fast way to check an object is a member of a list?

Martin Maechler maechler at stat.math.ethz.ch
Wed Nov 20 10:18:36 CET 2002


>>>>> "Francisco" == Francisco J Molina <fjmolina at lbl.gov>
>>>>>     on Tue, 19 Nov 2002 13:38:46 -0800 writes:

    Francisco> Is there any fast way to check that an object is
    Francisco> a member of a list?

I guess you want to check if a list has a certain *named* component?
Assume

   mylist <- list(ab = .., .....)

Then, you can use

   if(!is.null(mylist $ mycomp)) { .........}

or (not quite equivalently!)

   if("mycomp" %in% names(mylist)) { .........}

Does this answer the (little vague) question?
Regards,
Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list