[19115] in s-news-athena
[S] S-News Digest V1 #553
daemon@ATHENA.MIT.EDU (Thomas Wu)
Sun Sep 5 14:02:04 1999
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Date: Sun, 5 Sep 1999 10:53:43 -0700 (PDT)
From: Thomas Wu <thomas.wu@stanford.edu>
To: s-news@wubios.wustl.edu
Cc: paul.schwartz@cornell.edu
In-Reply-To: <199909050650.BAA27241@wubios.wustl.edu>
Message-Id: <14290.44438.988540.682943@exponential.org>
Paul,
One solution to your problem is
plotit <- function (y) {
df <- eval(as.name("mydataframe"))
boxplot(df$y)
}
There may be other solutions as well.
Thomas Wu, M.D., Ph.D.
thomas.wu@stanford.edu
> Date: Sat, 4 Sep 1999 22:10:32 -0400
> From: "Paul Schwarz" <Paul.Schwarz@cornell.edu>
> Subject: [S] need help writing a function
>
> Hello,
>
> I suspect that there is a simple solution to this programming problem,
> but so far it eludes me. I am trying to write a function that allows me
> to plot variables from a dataframe without specifying the name of the
> data frame (yes, I know that I could attach the data frame but please
> bear with me). The difficulty appears to be related to working with the
> names of data objects versus the objects themselves. The first approach
> I tried was to preserve both the dataframe name and the variable name as
> components of the data object. E.g.,
>
> plotit <- function( y ) {
> df <- mydataframe
> boxplot( df$y )
> }
>
> This seems to fail because df$y get evaluated as mydataframe$y, and the
> substitution of y never happens.
>
> The second approach I tried was to paste the dataframe name and the
> variable name together into a single string. However, I was unable to
> figure out how to coerce this string, which represents the name of the
> object, into a reference to the actual object. For example:
>
> plotit <- function( y ) {
> df <- "mydataframe"
> yvar <- paste( df, deparse( substitute( y ) ), sep = "$" )
> boxplot( yvar )
> }
>
> This fails because yvar is a string and not a reference to an object.
>
> I'd appreciate any tips or advice that you might have regarding this
> problem.
>
> Thank you.
>
> - -Paul
>
> Paul.Schwarz@Cornell.EDU
>
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news