Usage
rep(x, times = integer vector, length.out = non-negative integer, each = non-negative integer)
# default
rep(x, times = 1, length.out = NA, each = 1)
where:
- x is an object to replicate (a vector (of any mode including a list) or a factor or (for rep only) a POSIXct or POSIXlt or Date object; or an S4 object containing such an object.
- times is an non-Negative integer vector giving the number of times to repeat:
- each element if of length length(x),
- or to repeat the whole vector if of length 1
- length.out defines the desired length of the output vector. Other inputs will be coerced to an integer vector and the first element taken. Ignored if NA or invalid.
- each: non-negative integer. Each element of x is repeated each times.
Example
- Times 2
rep(1:4, 2)
[1] 1 2 3 4 1 2 3 4
- Each 10
rep(letters[1:3], each = 10)
[1] "a" "a" "a" "a" "a" "a" "a" "a" "a" "a" "b" "b" "b" "b" "b" "b" "b" "b" "b" "b" "c" "c"
[23] "c" "c" "c" "c" "c" "c" "c" "c"
Documentation / Reference
?rep