[R] filling values in a vector using smaller vector

Wacek Kusnierczyk Waclaw.Marcin.Kusnierczyk at idi.ntnu.no
Wed Dec 24 22:25:51 CET 2008


Milton Huang wrote:
> Thank you both for such beautiful solutions.  Just what I was looking for!  I 
> love the Internet, R, and the R-list!  There is so much opportunity to learn.  
> In fact, looking at the replace function, I see the two solutions are the 
> same:
>
>   
>> replace
>>     
> function (x, list, values)
> {
>     x[list] <- values
>     x
> }
> <environment: namespace:base>
>
>   

not exactly.  an application of replace generates a local copy of the
data, and whatever you pass to replace as x will not be modified, while
if you do the assignment yourself, you'll modify the data.


> Thanks again.  You made my day.  Have a happy holiday season.
>   

you too!  meRRy chRistmas and a happy new yeaR to all subscRibeRs.

vQ



More information about the R-help mailing list