[R] Using the get() function on an object within a list
dwinsemius at comcast.net
Tue Mar 30 23:45:23 CEST 2010
On Mar 30, 2010, at 5:23 PM, klc wrote:
> I am trying use the get function to return the value of an object
> within a
> list. As an abbreviated example:
> "original" represents a list of several objects, one of which is "a.
> names(original) <- c("a.1","a.2","a.3","b.1","b.2")
> original$a.1 <- c(4,3)
> When I enter:
> R returns the following vector
>  4 3
> however, when I enter:
 4 3
The get function will not parse and evaluate complex expressions for
you. And the "$" operator is probably not as useful for this
application as "[[" would be. See below
> R returns the following error:
> "Error in get("original$a.1") : object 'original$a.1' not found"
> Does anyone happen to know how to resolve this error?
> I pose this question because ultimately I would like to use the get
> to convert particular objects within "original" into separate lists
> species <- c(1,2,3)
> A <- vector('list',length(species))
> A <- lapply(paste("original$a.", species, sep=""), get)
> sapply(names(original), function(x) original[[x]])
 4 3
> sapply(1:3, function(x) original[[x]])
 4 3
> I apologize if I missed this question in a previous post.
> Many thanks-
> View this message in context: http://n4.nabble.com/Using-the-get-function-on-an-object-within-a-list-tp1745965p1745965.html
> Sent from the R help mailing list archive at Nabble.com.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT
More information about the R-help