Skip to content
Prev 75166 / 398502 Next

using <<- with a changing variable name (substitute?)

On Mon, 8 Aug 2005, Tamas K Papp wrote:

            
Why use sapply?

r[] <- ifelse(r >= d, r-d, ifelse(r >= 0, 0, r))

is one more efficient way.
If that is literally true, you cannot do this at R level AFAICS.  The only 
way I can see that you can do this with standard semantics is

m(r) <- d

with a replacement function m<-() written using .Call.  Using

"m<-" <- function(r, d) ifelse(r >= d, r-d, ifelse(r >= 0, 0, r))

is going to make several copies.