[R] how to not match partial names

From: William Revelle <lists_at_revelle.net>
Date: Sat, 07 May 2011 18:09:09 -0500


Dear friends,

How do I stop partial matching of list names?

e.g.,

x <- list(AAAA="aaaaa", BBBBB="bbbbb")
is.null(x$A) #returns FALSE even though there is no element A.

if(is.null(x$A)) {result <- x$BBBB} else {result <- x$A} result #is aaaa even though there is no x$A element

x <- list(CCCC="aaaaa", BBBBB="bbbbb")
if(is.null(x$A)) {result <- x$BBBB} else {result <- x$A} result #this is great

x <- list(ABC="aaaaa", BBBBB="bbbbb")
if(is.null(x$A)) {result <- x$BBBB} else {result <- x$A} result #partial matches and returns aaaa

x <- list(ABC="abc", BBBBB="bbbbb",AA="aaaa") if(is.null(x$A)) {result <- x$BBBB} else {result <- x$A} result #can not partial match, and thus returns bbbb

x <- list(AAB="aab", BBBBB="bbbbb",AA="aaaa") if(is.null(x$A)) {result <- x$BBBB} else {result <- x$A} result #also can not partial match

My need for this is that I have several functions that return lists and I am trying to extract AAAA if it exists, but something else if it does not.

Thanks.

Bill

-- 
William Revelle		http://personality-project.org/revelle.html
Professor			http://personality-project.org
Department of Psychology             http://www.wcas.northwestern.edu/psych/
Northwestern University	http://www.northwestern.edu/
Use R for psychology                       http://personality-project.org/r
It is 6 minutes to midnight	http://www.thebulletin.org

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sun 08 May 2011 - 00:14:24 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 08 May 2011 - 00:20:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive