Skip to content
Back to formatted view

Raw Message

Message-ID: <73f827b50901130249v395ca30bh573789a2d7ac6f7b@mail.gmail.com>
Date: 2009-01-13T10:49:16Z
From: Gundala Viswanath
Subject: Extracting Hash via Vector

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