用默认值填充数组

数组和集合 / 数组

value <- 5
count <- 3
filled <- rep(value, count)
# filled = 5 5 5

# times 重复整个向量
repeated <- rep(c(1, 2), times = count)
# repeated = 1 2 1 2 1 2

# each 重复每个元素
each_repeated <- rep(c(1, 2), each = count)
# each_repeated = 1 1 1 2 2 2

# 把向量作为一个整体值:用列表包起来
pairs <- rep(list(c(1, 2)), count)

cat("filled =", filled, "\n")
cat("repeated =", repeated, "\n")
cat("each_repeated =", each_repeated, "\n")
str(pairs)