Array filled with a default value

Arrays and collections / Arrays

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

# times repeats the whole vector
repeated <- rep(c(1, 2), times = count)
# repeated = 1 2 1 2 1 2

# each repeats every element
each_repeated <- rep(c(1, 2), each = count)
# each_repeated = 1 1 1 2 2 2

# A vector as one value: wrap it in a list
pairs <- rep(list(c(1, 2)), count)

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