在r中重复一些元素

Bil*_*lal 2 r vector seq rep

我有一个包含以下内容的向量:

my.var <- c("a","b","c","d","e","f")
my.var
[1] "a" "b" "c" "d" "e" "f"
Run Code Online (Sandbox Code Playgroud)

我想只使用repseq函数来解决这个问题:

"a" "b" "c" "b" "c" "d" "c" "d" "e" "d" "e" "f"
Run Code Online (Sandbox Code Playgroud)

luk*_*keA 8

要么

x <- c("a","b","c","d","e","f")
n <- 3
x[seq_len(n)+rep(0:(length(x)-n), each=n)]
# [1] "a" "b" "c" "b" "c" "d" "c" "d" "e" "d" "e" "f"
Run Code Online (Sandbox Code Playgroud)