[R] insert number in vector

David Scott d.scott at auckland.ac.nz
Tue Jun 18 23:24:49 CEST 2002


On Tue, 18 Jun 2002, Juan Ramon Gonzalez wrote:

> Hello R-users,
>
>
> I need to create a vector inserting an 1 after each value of another vector.
> For example:
>
> vec1<-c(2,3,4)
>
> I need to create a vector with the values 2,1,3,1,4
>
>
How about:

n<-length(vec1)
odd<-2*(1:n)-1
vec2<-rep(1,2*n)
vec2[odd]<-vec1

David Scott
_________________________________________________________________
David Scott     Department of Statistics
                Tamaki Campus
                The University of Auckland, PB 92019
                Auckland        NEW ZEALAND
Phone: +64 9 373 7599 ext 6830     Fax: +64 9 373 7000
Email:  d.scott at Auckland.ac.nz

Webmaster, New Zealand Statistical Association:
	http://www.stat.auckland.ac.nz/nzsa/

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list