为从不同起点连续增加的 4 个数字创建 R 序列

Creating R Sequence for 4 numbers increasing consecutively from different starting points

我在 R 方面有经验,但在序列方面几乎没有经验。

我想做一个数字序列,以前4个数字为起点,连续递增。即:

5,72,144,210,[now I repeat each +1], 6,73,145,211,[and so on],7,74,146,212

因此:

c(5,72,144,210,6,73,145,211,7,74,146,212..)

非常感谢任何关于如何设置它的想法。例如,我需要它继续进行 60 次迭代。

类似于:

x <- c(5,72,144,210)
rep(x, 60) + rep(0:59, each=length(x))

或者使用 Ronak Shah 提到的 R 回收:

x + rep(0:59, each=length(x))

或者:

as.vector(do.call(rbind, lapply(c(5,72,144,210), function(k) k:(k+60))))

输出:

  [1]   5  72 144 210   6  73 145 211   7  74 146 212   8  75 147 213   9  76 148 214  10  77 149 215
 [25]  11  78 150 216  12  79 151 217  13  80 152 218  14  81 153 219  15  82 154 220  16  83 155 221
 [49]  17  84 156 222  18  85 157 223  19  86 158 224  20  87 159 225  21  88 160 226  22  89 161 227
 [73]  23  90 162 228  24  91 163 229  25  92 164 230  26  93 165 231  27  94 166 232  28  95 167 233
 [97]  29  96 168 234  30  97 169 235  31  98 170 236  32  99 171 237  33 100 172 238  34 101 173 239
[121]  35 102 174 240  36 103 175 241  37 104 176 242  38 105 177 243  39 106 178 244  40 107 179 245
[145]  41 108 180 246  42 109 181 247  43 110 182 248  44 111 183 249  45 112 184 250  46 113 185 251
[169]  47 114 186 252  48 115 187 253  49 116 188 254  50 117 189 255  51 118 190 256  52 119 191 257
[193]  53 120 192 258  54 121 193 259  55 122 194 260  56 123 195 261  57 124 196 262  58 125 197 263
[217]  59 126 198 264  60 127 199 265  61 128 200 266  62 129 201 267  63 130 202 268  64 131 203 269