This seems odd. When I try to look up a list element which has a space in the name using just the first word (i.e. no spaces), it will sometimes return the element with a space in the name and sometimes it will return NULL. Try this: alist <- list( 'hello'=10, bye=20, 'hello world'=30, 'goodbye world'=40, 'hi world'=50, 'goodbye foo'=60, 'goodbye bar'=70) Then try fetching some list elements:> alist[['goodbye']]NULL> alist[['hi']][1] 50> alist[['hello']][1] 10 With "goodbye" there were a couple list elements with spaces in the name, so it didn't return any of them. With "hi" there was one (and only one) element which had "hi" as the first word: "hi world" With "hello" there was an actual element named "hello" This seems messed up and non-intuitive to say the least. I am doing this on R version 2.5.0 (2007-04-23) compiled on a itanium64 and I also tried it on R version 2.5.1 (2007-06-27) on an pentium 4 ubuntu linux [[alternative HTML version deleted]]
Hi, I have tried this with R-2.7.2 then I got> alist[['goodbye']]NULL> alist[['hi']]NULL> alist[['hello']][1] 10 The results make sense to me thus you might want to update your R version. chunhao B Fox wrote:> > This seems odd. When I try to look up a list element which has a space in > the name using just the first word (i.e. no spaces), it will sometimes > return the element with a space in the name and sometimes it will return > NULL. > > Try this: > > alist <- list( 'hello'=10, bye=20, 'hello world'=30, 'goodbye world'=40, > 'hi > world'=50, 'goodbye foo'=60, 'goodbye bar'=70) > Then try fetching some list elements: >> alist[['goodbye']] > NULL >> alist[['hi']] > [1] 50 >> alist[['hello']] > [1] 10 > With "goodbye" there were a couple list elements with spaces in the name, > so > it didn't return any of them. > > With "hi" there was one (and only one) element which had "hi" as the first > word: "hi world" > > With "hello" there was an actual element named "hello" > > This seems messed up and non-intuitive to say the least. > > I am doing this on R version 2.5.0 (2007-04-23) compiled on a itanium64 > and I also tried it on R version 2.5.1 (2007-06-27) on an pentium 4 ubuntu > linux > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > >-- View this message in context: http://www.nabble.com/Bug-or-feature-with-finding-a-list-element--tp19773038p19773259.html Sent from the R help mailing list archive at Nabble.com.
I think you will find that this follows the partial matching rules: * exact match * unique partial match * take evasive action if non-unique partial match Patrick Burns patrick at burns-stat.com +44 (0)20 8525 0696 http://www.burns-stat.com (home of S Poetry and "A Guide for the Unwilling S User") B Fox wrote:> This seems odd. When I try to look up a list element which has a space in > the name using just the first word (i.e. no spaces), it will sometimes > return the element with a space in the name and sometimes it will return > NULL. > > Try this: > > alist <- list( 'hello'=10, bye=20, 'hello world'=30, 'goodbye world'=40, 'hi > world'=50, 'goodbye foo'=60, 'goodbye bar'=70) > Then try fetching some list elements: > >> alist[['goodbye']] >> > NULL > >> alist[['hi']] >> > [1] 50 > >> alist[['hello']] >> > [1] 10 > With "goodbye" there were a couple list elements with spaces in the name, so > it didn't return any of them. > > With "hi" there was one (and only one) element which had "hi" as the first > word: "hi world" > > With "hello" there was an actual element named "hello" > > This seems messed up and non-intuitive to say the least. > > I am doing this on R version 2.5.0 (2007-04-23) compiled on a itanium64 > and I also tried it on R version 2.5.1 (2007-06-27) on an pentium 4 ubuntu > linux > > [[alternative HTML version deleted]] > > ______________________________________________ > 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. > > >