[R] Repeating sequence elements
arun
smartpink111 at yahoo.com
Fri May 17 14:54:25 CEST 2013
Hi,
rep(seq_along(v),v)
#[1] 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6
A.K.
----- Original Message -----
From: Stefan Petersson <stefan at inizio.se>
To: r-help at r-project.org
Cc:
Sent: Friday, May 17, 2013 6:53 AM
Subject: [R] Repeating sequence elements
I want to create a sequence, repeating each element according to a vector.
I have this:
v <- c(4, 4, 4, 3, 3, 2)
And want to create this:
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 5 5 5 6 6
TIA
// s
R version 3.0.0 (2013-04-03)
Platform: x86_64-pc-linux-gnu (64-bit)
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=C LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
[[alternative HTML version deleted]]
______________________________________________
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.
More information about the R-help
mailing list