On Tue, 18 Feb 2003 07:47:56 -0800 (PST), "Thomas Lumley"
<[EMAIL PROTECTED]> said:
> history()
> a<-c(1,2,3,5,6,3)
> N<-length(a)
> threes<- a==3
> offset<- c(0,cumsum(threes)[-N])
> a[offset+(1:N)]<-a
> a[which(threes)+offset[threes]+1]<-7

> On Tue, 18 Feb 2003 [EMAIL PROTECTED] wrote:
<...>
> > The problem is that it is placing the '7's in the correct place, but is
> > not shifting the right-hand side of the list across to make room.
> 
> The code does work, but you have to use all of it, not just that line.
> The *previous* line does the shifting.

D'oh! Of course!

Now that *is* a clever solution. :-)
-- 
  Jeremy Howard
  [EMAIL PROTECTED]

______________________________________________
[EMAIL PROTECTED] mailing list
http://www.stat.math.ethz.ch/mailman/listinfo/r-help

Reply via email to