[R] To transform a vector

Pascal Oettli kridox at ymail.com
Mon Dec 9 08:14:46 CET 2013


Hello,

Are you looking for Y <- rep(X, X) ?

Regards,
Pascal

On 9 December 2013 16:04, Arnaud Michel <michel.arnaud at cirad.fr> wrote:
> Dear R Users
>
> I have the vector
> X <- c( 6 , 4 ,12 , 3)
>
> I would like to build a new vector by to transform it into
> Y <- c(rep(X[1], X[1]), rep(X[2], X[2]), rep(X[3], X[3]), rep(X[4], X[4]))
>
> Have you a more elegant answer ?
>
> PS : Sorry for this basic question
>
> --
> Michel ARNAUD
> Chargé de mission auprès du DRH
> DGDRD-Drh - TA 174/04
> Av Agropolis 34398 Montpellier cedex 5
> tel : 04.67.61.75.38
> fax : 04.67.61.57.87
> port: 06.47.43.55.31
>
> ______________________________________________
> 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.



-- 
Pascal Oettli
Project Scientist
JAMSTEC
Yokohama, Japan



More information about the R-help mailing list