Message-ID: <15835.21356.680460.461311@gargle.gargle.HOWL>
Date: 2002-11-20T09:18:36Z
From: Martin Maechler
Subject: fast way to check an object is a member of a list?
In-Reply-To: <15834.44902.250929.416541@0-e0-98-8a-c5-4a.dhcp.lbl.gov>
>>>>> "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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._