[R] %+=% and eval.parent()
    Gabor Grothendieck 
    ggrothendieck at myway.com
       
    Tue Apr  6 16:18:42 CEST 2004
    
    
  
Robin Hankin <rksh <at> soc.soton.ac.uk> writes:
> R> a <- matrix(1:9,3,3)
> But the following caught me off-guard:
> R> a <- matrix(1:9,3,3)
> R> a[a%%2==1] %+=% 1000*(1:5)
How about this way:
> a <- matrix(1:9,3,3)
> "plus<-" <- function(a,value) a+value
> plus(a[a%%2==1]) <- 1000*(1:5)
> a
     [,1] [,2] [,3]
[1,] 1001    4 4007
[2,]    2 3005    8
[3,] 2003    6 5009
>
    
    
More information about the R-help
mailing list