rep(x, ...) rep.int(x, times) rep_len(x, length.out) ## Default S3 method: rep(x=NULL, times = 1, length.out = NA, each = 1) ## S3 method for class 'factor': rep(x, ...) ## S3 method for class 'Date': rep(x, ...) ## S3 method for class 'POSIXct': rep(x, ...) ## S3 method for class 'POSIXlt': rep(x, ...)
x | a vector. Missing values (NAs) are allowed. |
... | additional arguments to be passed to other methods. |
times |
the number of times to replicate x.
You can specify either a single value or a numeric vector.
An error is returned if the length of times is neither 1 nor the length of x. |
length.out |
the length of the result. You can
use this argument instead of times, in which case x is
replicated as needed to produce a result with length.out data
values.
times is ignored if you specify values for both length.out and times. |
each | the number of times to repeat each element of x. This vector is repeated if you specify a value for either times or length.out. |
rep(0, 100) # 100 zeros # 1, 2, 3, 4 repeated until there are 48 numbers rep(1:4, length.out=48) rep(1:10, 10) # 10 repetitions of 1:10 rep(1:10, 1:10) # 1, 2, 2, 3, 3, 3, ... rep(1:5, each=2) # 1, 1, 2, 2, 3, 3, 4, 4, 5, 5 rep(1:3, 5, each=2) # same as rep( c(1, 1, 2, 2, 3, 3), 5)## Date/POSIXt rep(as.Date(c("1970-01-01", "2038-01-19")), length.out = 5) rep(as.POSIXct(c("1970-01-01", "2038-01-19")), times = 2, each = 3) rep(as.POSIXlt(c("1970-01-01", "2038-01-19")), length.out = 5, each = 3)
rep.int(1:3, 1:3) # 1, 2, 2, 3, 3, 3 rep_len(1:3, 5) # 1, 2, 3, 1, 2