[R] fast value replacement in (numeric) vector

hadley wickham h.wickham at gmail.com
Sat Sep 20 23:49:27 CEST 2008


On Sat, Sep 20, 2008 at 4:41 PM, Ling, Gary (Electronic Trading)
<Gary_Ling at ml.com> wrote:
> Hi R users,
> What is the fastest way to replace a(some) value(s) in a (numeric)
> vector?
> I checked ?replace, but its output is another vector.
> 1) I wonder if there's any function to perform in-place replacement?
> 2) Or any other function would do what I'm looking for with faster
> speed?
>
> # here is something I tried in R:
> n <- 100000
> L <- 1:n

L[1] <- 0
L[n] <- 0

L[c(1, n)] <- 0

?

Hadley

-- 
http://had.co.nz/



More information about the R-help mailing list