[R] insert number in vector
Mike Lonergan
mel at mcs.st-and.ac.uk
Tue Jun 18 13:20:45 CEST 2002
Or even:
> c(rbind(Vec,1))
[1] 2 1 3 1 4 1
It is a lovely language!
Cheers,
Mike.
> -----Original Message-----
> From: owner-r-help at stat.math.ethz.ch
> [mailto:owner-r-help at stat.math.ethz.ch]On Behalf Of Peter Malewski
> Sent: 18 June 2002 10:28
> To: r-help at stat.math.ethz.ch
> Subject: Re: [R] insert number in vector
>
>
> > c(t(cbind(Vec,rep(1,length(Vec)))))
> [1] 2 1 3 1 4 1
>
> P.
>
>
>
> On Tue, Jun 18, 2002 at 10:51:20AM +0200, Peter Dalgaard BSA wrote:
> > "Juan Ramon Gonzalez" <jrgonzalez at ico.scs.es> writes:
> >
> > > 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
> > >
> > >
> > > Does anyone know how create this vector without loops
> (vec1 could have 1000
> > > elements)
> >
> > something like
> >
> > result <- rep(1, 2*length(vec1)-1)
> > result[seq(1, length(result), 2)] <- vec1
> >
> > --
> > O__ ---- Peter Dalgaard Blegdamsvej 3
> > c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
> > (*) \(*) -- University of Copenhagen Denmark Ph:
> (+45) 35327918
> > ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX:
> (+45) 35327907
> >
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> .-.-.-.-.-.-.-.-.-
> > 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
> >
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> ._._._._._._._._._
>
> --
> P.Malewski, Limmerstr.47, 30451 Hannover, 0511-2135008
> At work: http://www.MH-Hannover.de 0511 532 3194 / Fax: 0511
> 532 3190,
> P.Malewski at tu-bs.de, peter.malewski at gmx.de,
> malewski.peter at mh-hannover.de.
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> .-.-.-.-.-.-.-.-.-
> 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
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> ._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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