[R] adding sequence for each value in a vector
Liaw, Andy
andy_liaw at merck.com
Thu Oct 27 17:15:00 CEST 2005
Here's one way:
> unlist(lapply(x, function(x) x:(x+9)))
[1] 1 2 3 4 5 6 7 8 9 10 15 16 17 18 19 20 21 22
23 24
[21] 30 31 32 33 34 35 36 37 38 39 45 46 47 48 49 50 51 52
53 54
[41] 60 61 62 63 64 65 66 67 68 69 90 91 92 93 94 95 96 97
98 99
[61] 115 116 117 118 119 120 121 122 123 124
Andy
> From: Yves Magliulo
>
> hi,
>
> i have a vector like :
>
> x<-c(1,15,30,45,60,90,115)
>
> i know that step by step i have always more than 10
>
> min(diff(x)) >=11
>
> i want to add for each value a sequence of value:value+9
> result should be :
>
> 1 2 3 4 5 6 7 8 9 10 15 16 17 18 19 20 21 22 23 24 30 31
> (...) 39 45 46
> (...) 54 60 61 etc..
>
> how can i do this without a loop (i'm sure there is a
> "elegant" way like
> always with R but i can't find it this time!)
>
> best,
>
> yves
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
More information about the R-help
mailing list