s-news
[Top] [All Lists]

using get() to extract a vector from a data frame

To: <s-news@lists.biostat.wustl.edu>
Subject: using get() to extract a vector from a data frame
From: "Jeff P. Hollenbeck" <Jeff.Hollenbeck@oregonstate.edu>
Date: Thu, 13 Mar 2008 14:16:21 -0800
Organization: Oregon State University
References: <005a01c88471$6895ae70$1200a8c0@jackstraw>
This is very similar to my previous post on this problem, but I have pinned down my issue.  Perhaps someone on this list would be kind enough to help me solve this.
 
I am trying to extract a vector (column) from a data frame using the code below.  I first define the data frame and target vector (column) names as variables.  Then I attempt to use get() to extract the target vector.  That is where I am having difficulty.  Here is the code
 
#
# Get response variable name components.
data <- as.character(multinom.model@call[[3]])
yvar <- as.character(multinom.model@formula[[2]])
#
# Extract response (y) vector.
y <- get(data)$yvar
#
 
The problem is the way yvar gets treated in the get statement.  I know this because if I manually replace yvar with a valid column name, I get the correct behavior.  I simply have no idea how to get yvar to be treated correctly in the get() statement.   As it is now, I get NULL result for y.  Any help here is much appreciated.
 
Thank you very much,
 
jeff.
 
Jeff P. Hollenbeck
Dept. Forest Resources
Oregon State University
Corvallis OR 97330
Email: Jeff.Hollenbeck@oregonstate.edu
Phone: 541-737-5500
<Prev in Thread] Current Thread [Next in Thread>