从数据帧向量中的连续模式中提取元素

Extracting the elements from the consecutive pattern in the dataframe vector

我有一个包含 30,000 多个值的数据框,如下所示

1   qw
2   as
3   we
4   er
5   rt
6   @@@@
7   @@@@
8   @@@@
9   @@@@
10  as
11  df
12  fg
13  gh
14  hj

我想提取位置索引 1、3、5、10、12、14、19、21、23 等处的值。作为初学者,我知道使用 seq(first, last, by=) 提取价值,但我无法按照上述模式进行切片。

1   qw
3   we
5   rt
10  as
12  fg
14  hj

像这样嵌套一些东西对你有用:

> rep(seq(1, 5, 2), 3) + rep(seq(0, 18, 9), each = 3)
[1]  1  3  5 10 12 14 19 21 23

更多价值:

nMax <- 30000

seq1 <- seq(1, 5, 2)
seq2 <- rep(seq(0, nMax, 9))

rep(seq1, length(seq2)) + rep(seq2, each = 3)