Skip to content
Prev 127842 / 398500 Next

Executing a Function in a Loop With a ChangingValue foran Argument

I wondered if the real problem was bigger than your abstract version.
OK.  Here is one way to do it
nam <- deparse(substitute(x))
    val <- mean(x)
    cat("mean(", nam, ") =", val, "\n")
    invisible(val)
    }
list(...)))
[1] "X2" "X3" "X4" "X5"
mean( X2 ) = -0.08661249 
mean( X3 ) = 0.009840606 
mean( X4 ) = -0.21054 
mean( X5 ) = 0.07321301
X2           X3           X4           X5 
-0.086612490  0.009840606 -0.210540008  0.073213012
Now why do I suspect there is something more as well....hmmm...? 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile:                         +61 4 8819 4402
Home Phone:                     +61 7 3286 7700
mailto:Bill.Venables at csiro.au
http://www.cmis.csiro.au/bill.venables/ 

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Rick Bilonick
Sent: Thursday, 25 October 2007 4:13 PM
To: R Help
Subject: Re: [R] Executing a Function in a Loop With a ChangingValue
foran Argument
On Thu, 2007-10-25 at 15:34 +1000, Bill.Venables at csiro.au wrote:
Thanks. The problem with this approach is that the data.frame variable
names are lost. (A minor point is that it won't work if only one
variable is chosen.) The function I wrote generates labels for a plot
and I want the variable name to show up (not "i"). I was hoping not to
have to re-write my function. Is there a way to pass the variables that
will allow my function to work normally (just as it would if I wrote out
the function calls with the names manually inserted)? (I would assume
that any function that generates a character variable from the variable
name is not going to produce the desired result.)

Rick B.

______________________________________________
R-help at 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.