Dear list,
I have two functions created in the same environment, fun1 and fun2.
fun2 is called by fun1, but fun2 should use an object which is created in fun1
fun1 - function(x) {
ifelse(somecondition, bb - o, bb - *)
## mymatrix is created, then
myresult - apply(mymatrix, 1, fun2)
}
-help@stat.math.ethz.ch
Sent: Wednesday, August 09, 2006 5:21 PM
Subject: [R] objects and environments
Dear list,
I have two functions created in the same environment, fun1 and fun2.
fun2 is called by fun1, but fun2 should use an object which is
created in fun1
fun1 - function(x
On Wednesday 09 August 2006 18:31, Dimitris Rizopoulos wrote:
try this:
fun1 - function(x) {
environment(fun2) - environment()
ifelse(somecondition, bb - o, bb - *)
## mymatrix is created, then
myresult - apply(mymatrix, 1, fun2)
}
Beautiful :)
Thanks very much Dimitris, I
Dmitris has already provided the solution but just throught I would'
mention that your third alternative can be written:
apply(mymatrix, 1, fun2, bb = bb)
(assuming fun2 has arguments idx and bb) which is not
nearly so ugly so you might reconsider whether its ok
for you to just pass bb.
On
On Wednesday 09 August 2006 19:14, Gabor Grothendieck wrote:
Dmitris has already provided the solution but just throught I would'
mention that your third alternative can be written:
apply(mymatrix, 1, fun2, bb = bb)
(assuming fun2 has arguments idx and bb) which is not
nearly so ugly so you