Re: [R] modifynig some elements of a vector

2011-02-10 Thread William Dunlap
t.org] On Behalf Of Eric Elguero > Sent: Thursday, February 10, 2011 3:50 AM > To: r-help@r-project.org > Subject: [R] modifynig some elements of a vector > > He everybody, > > I want to add 1 to some elements of a vector: > > x is a vector > u is a vector of idices

Re: [R] modifynig some elements of a vector

2011-02-10 Thread Petr Savicky
On Thu, Feb 10, 2011 at 12:50:03PM +0100, Eric Elguero wrote: > He everybody, > > I want to add 1 to some elements of a vector: > > x is a vector > u is a vector of idices, that is, integers > assumed to be within the range 1..length(x) > and I want to add 1 to the elements of x > each time thei

Re: [R] modifynig some elements of a vector

2011-02-10 Thread jim holtman
should be able to: u <- unique(u) x[u] <- x[u] + 1 On Thu, Feb 10, 2011 at 6:50 AM, Eric Elguero wrote: > He everybody, > > I want to add 1 to some elements of  a vector: > > x is a vector > u is a vector of idices, that is, integers > assumed to be within the range 1..length(x) > and I want to

[R] modifynig some elements of a vector

2011-02-10 Thread Eric Elguero
He everybody, I want to add 1 to some elements of a vector: x is a vector u is a vector of idices, that is, integers assumed to be within the range 1..length(x) and I want to add 1 to the elements of x each time their index appears in u x[u]<-x[u]+1 works only when there are no duplicated value