[R] Adding to the middle of a vector
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Mon Sep 7 20:01:15 CEST 2009
have a look at ?append(), e.g.,
x <- 101:110
append(x, 200, after = 4)
I hope it helps.
Best,
Dimitris
Dennis Fisher wrote:
> Colleagues,
>
> Assume that I have a vector with N elements
> Vector <- 101:110).
>
> I would like to interpose an element into the vector at a position other
> than the start or end:
> c(101:104, 200, 105:110).
>
> I could do the following:
> NewVector <- c(Vector[1:4], NewElement, Vector[5:10])
>
> However, I suspect that there is a more elegant solution.
>
> Any proposals?
>
> Dennis
>
>
> Dennis Fisher MD
> P < (The "P Less Than" Company)
> Phone: 1-866-PLessThan (1-866-753-7784)
> Fax: 1-415-564-2220
> www.PLessThan.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
More information about the R-help
mailing list