Message-ID: <200411220929.06611.deepayan@stat.wisc.edu>
Date: 2004-11-22T15:29:06Z
From: Deepayan Sarkar
Subject: How to insert one element into a vector?
In-Reply-To: <41A2038C.5080002@lancaster.ac.uk>
On Monday 22 November 2004 09:19, Barry Rowlingson wrote:
> michael watson (IAH-C) wrote:
> > There must be a million ways of doing this!
>
> Actually I'd say there were no ways of doing this, since I dont
> think you can actually insert into a vector - you have to create a
> new vector that produces the illusion of insertion!
>
> Here's a Q+D function that fails if you try and insert at the
> start, or at the end. Its very D.
>
> insert <- function(v,e,pos){
> return(c(v[1:(pos-1)],e,v[(pos):length(v)]))
> }
Pretty much what 'append' does.
Deepayan