[R] How to define a function (with '<-') that has two arguments?
Hadley Wickham
hadley at rice.edu
Wed Jul 14 11:29:06 CEST 2010
On Wed, Jul 14, 2010 at 7:39 AM, thmsfuller066 at gmail.com
<thmsfuller066 at gmail.com> wrote:
> Hi All,
>
> The last line if the following code returns the error right below this
> paragraph. Essentially, I use the operator %:% to retrieve a variable
> in a nested frame. Then I want to use the same operator (with '<-') to
> change its value. I'm not sure if this is possible in R with %:%
> operator. Would you please help and let me how to correct the code if
> it is possible?
Why not just do
e1$e2$a <- 3
?
If you are trying to do something more complicated, it may help to
understand that e1 %:% e2 %:% a <- 3 is effectively the same as
tmp1 <- e1 %:% e2
tmp1 %:% a <- 3
tmp2 <- e1
tmp2 %:% e2 <- tmp1
e1 <- tmp2
so your %:%<- function is going to get called multiple times.
Hadley
--
Assistant Professor / Dobelman Family Junior Chair
Department of Statistics / Rice University
http://had.co.nz/
More information about the R-help
mailing list