如何根据变量计数返回所有变量的列表?

时间:2018-07-26 20:52:18

标签: r count duplicates return

所以我有一列用于变量,一列用于计数。

vars <- c("a","b","c","d","e")
counts <- c(1,3,2,3,0) 

我想返回的列表/向量

"a" "b" "b" "b" "c" "c" "d" "d" "d"

有什么提示吗?

1 个答案:

答案 0 :(得分:1)

使用rep

rep(vars, times = counts)
#[1] "a" "b" "b" "b" "c" "c" "d" "d" "d"