[R] Insert elements into a vector in a defined positions

Manuel Ramon manugen at gmail.com
Wed Nov 25 22:46:53 CET 2009


Dear R users,
I have a vector of length n and I want to insert some elements (in my case
the NA string) into a defined positions. For example, my vector is z1 and I
want to add NA's in positions 4, 6 y 7 so after that, my new vector, z2,
should have a length of 10+3. 

  z1 <- 1:10
  id <- c(4,6,7)

  # And z2 should be: 
  z2 <- c(1,2,3,NA,4,5,NA,NA,6,7,8,9,10)

Anyone knows how can I do that?
Thank you.

-----
Manuel Ramón Fernández
Group of Reproductive Biology (GBR)
University of Castilla-La Mancha (Spain)
mramon at jccm.es
-- 
View this message in context: http://old.nabble.com/Insert-elements-into-a-vector-in-a-defined-positions-tp26520841p26520841.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list