[R] Vector manipulation
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Sun Feb 12 19:02:40 CET 2012
One way is:
vec <- c(2,4,6,9,10)
c(rbind(vec[1], vec[-1]))
I hope it helps.
Best,
Dimitris
On 2/12/2012 6:54 PM, syrvn wrote:
> Hello,
>
>
> I am stuck with the following problem. Consider the vector:
>
> vec<- c(2,4,6,9,10)
>
> I now want to use R to manipulate the vector as follows:
>
> [1] 2, 4, 2, 6, 2, 9, 2, 10
>
> In words, the first element of the vector should be placed in front of each
> following number.
>
> Which R commands do I need to achieve that?
>
>
> Cheers
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Vector-manipulation-tp4381586p4381586.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
More information about the R-help
mailing list