# Repeat the entire vector
vec_rep(1:2, 3)
# Repeat within each vector
vec_rep_each(1:2, 3)
x <- vec_rep_each(1:2, c(3, 4))
x
# After using `vec_rep_each()`, you can recover the original vector
# with `vec_unrep()`
vec_unrep(x)
df <- data.frame(x = 1:2, y = 3:4)
# `rep()` repeats columns of data frames, and returns lists
rep(df, each = 2)
# `vec_rep()` and `vec_rep_each()` repeat rows, and return data frames
vec_rep(df, 2)
vec_rep_each(df, 2)
# `rle()` treats adjacent missing values as different
y <- c(1, NA, NA, 2)
rle(y)
# `vec_unrep()` treats them as equivalent
vec_unrep(y)
Run the code above in your browser using DataLab