#Build your career, now 50% off
#Buy Now

#RDocumentation

#Learn R
#Search all packages and functions
#Search all packages and functions
#base (version 3.6.2)
#rep: Replicate Elements of Vectors and Lists
#Description
#rep replicates the values in x. It is a generic function, and the (internal) default method is described here.

#rep.int and rep_len are 
#Usage

#Arguments

#an integer-valued vector giving the (non-negative) number of times to repeat each element if of length length(x), or to repeat the whole vector if of length 1. Negative or NA values are an error. A  many times as is necessary to create a vector of this length. If both are given, length.out takes priority and times is ignored.es will be truncated towards zero. If times is a . M. and Wilks, A. R. (1988) The New S Language. Wadsworth & Brooks/Cole.
# NOT RUN {
rep(1:4, 2)
rep(1:4, each = 2)       # not the same.
rep(1:4, c(2,2,2,2))     # same as second.
rep(1:4, c(2,1,2,1))
rep(1:4, each = 2, len = 4)    # first 4 only.
rep(1:4, each = 2, len = 10)   # 8 integers plus two recycled 1's.
rep(1:4, each = 2, times = 3)  # length 24, 3 complete replications

rep(1, 40*(1-.8)) # length 7 on most platforms
rep(1, 40*(1-.8)+1e-7) # better

## replicate a list
fred <- list(happy = 1:10, name = "squash")
rep(fred, 5)

# date-time objects
x <- .leap.seconds[1:3]
rep(x, 2)
rep(as.POSIXlt(x), rep(2, 3))

## named factor
x <- factor(LETTERS[1:4]); names(x) <- letters[1:4]
x
rep(x, 2)
rep(x, each = 2)
rep.int(x, 2)  # no names
rep_len(x, 10)
# }

Embed on website

To embed this program on your website, copy the following code and paste it into your website's HTML: