Which R version do you have? I'm asking this because my 2.7.0 gives a different error message:
> x[[q]] Error in x[[q]] : recursive indexing failed at level 2 Anyway, as Wacek said, x[[q]] is equivalent to x[["some"]][["more"]][["not_there"]] -- and you don't have an element called "more" in x[["some"]]. But you can use [ to do what you want (if the following is what you want). > x[q] $some [1] 0.1118383 $more [1] 0.4524315 $<NA> NULL KK On Tue, Jan 13, 2009 at 12:49 PM, Gundala Viswanath <gunda...@gmail.com>wrote: > Dear all, > > Suppose I have a hash created with this > > x <- list() > for (i in c('test', 'some', 'more')){ > x[[i]] <- runif(1) > } > > then I want to extract the elem of that hash with > a vector > > > q <- c("some", "more", "not_there") > > But why this failed? > > > extracted <- x[[q]] > Error in x[[q]] : subscript out of bounds > > we expect the output of 'extracted' to be > a vector as well. When the key is not present > to give "NA" in vector > > - Gundala Viswanath > Jakarta - Indonesia > > ______________________________________________ > R-help@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. > [[alternative HTML version deleted]] ______________________________________________ R-help@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.