[R] How to insert one element into a vector?

Barry Rowlingson B.Rowlingson at lancaster.ac.uk
Mon Nov 22 16:43:01 CET 2004


Deepayan Sarkar wrote:

> Pretty much what 'append' does.

  A shame then, that help.search("insert") doesn't find 'append'! I cant 
think why anyone looking for a way of _inserting_ a value in the middle 
of a vector would think of looking at "append"!

  Python has separate insert and append methods for vectors.

  >>> x=[1,2,3,4,6]
  >>> x.insert(4,5)
  >>> x
  [1, 2, 3, 4, 5, 6]
  >>> x.append(99)
  >>> x
  [1, 2, 3, 4, 5, 6, 99]


Barry




More information about the R-help mailing list