Skip to content
Prev 28277 / 398498 Next

inserting elements in a list

On 17 Feb 2003 20:11:11 +0100, "Peter Dalgaard BSA"
<p.dalgaard at biostat.ku.dk> said:
Indeed they're not - and the code above fails to do this insertion:
[1]  1  2  3  7  6  3 NA  7

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.
That's a neat way to find the right spots to place the '7's - wherever
the '3's were before, plus one spot for each '3' that we've seen so
far... I'm not sure how to insert into the vector rather than replace
though - a quick browse through the list archives didn't turn up any
quick solutions (other than the types of loops suggested in earlier
answers in this thread).