Use of rep function in R

The official help document reads as follows:
Usage

rep(x, ...)

rep.int(x, times)

rep_len(x, length.out)

Arguments

x 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.
... further arguments to be passed to or from other methods. For the internal default method these can include:

times

An integer vector giving the (non-negative) number of times to repeat each element if of length length(x), Negative or NA values are an error.

length.out

The desired length of The output vector. Other inputs will be coerced into 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. Other inputs will be coerced into an integer vector and the first element taken As 1 if NA or invalid.

times

see ... .
length.out non-negative integer: the desired length of the output vector.

Rep functions with four parameters: the x vector or class vector of objects, each: x elements each repetitions, times: after each vector processing, if The Times is a single value, is the value of the whole after each repeat number of times, if it is equal to the vector x after each of the length of the vector, for each of the number of the elements of the repeat times each element in the same position, otherwise an error; Leng. out refers to the length of the final output of the vector processed by times. If it is longer than the generated vector, it is completed. That is, rep will take each parameter, generate a vector X1, and times will manipulate X1 to generate X2, lengthen. Out will manipulate X2 to produce the final output vector X3. Here is an example:
> Rep (1:4,times=c(1,2,3,4)) # and vector x equal length times mode
[1] 1 2 2 3 3 3 4 4 4 4
> Rep (1:4,times=c(1,2,3)) # non-equilong mode, Error
Error in rep(1:4,times=c(1,2,3)) : invalid 'times' argument
> Rep (1:4,each=2,times=c(1,2,3,4)) # is still non-equal length mode, because the vector after each has 8 bits, instead of 4 bits
Error in rep(1:4,each=2,times=c(1,2,3,4)) :
invalid 'times' argument
> Rep (1:4, times = c (1, 2, 3, 4)) # isometric model, I wrote to the o (╯/╰) o
[1] 1 2 2, 3, 3, 3, 4, 4 4 4
& gt; Rep (1:4,times=c(1,2,3,4),each=3) # repeat example, don't beat me
Error in rep(1:4,times=c(1,2,3,4),each=3) :
invalid 'times' argument
> Rep (1:4, each = 2, times = 8) # value correctly, times8 bit length vector
[1] 1 1 1 2 2 2 2 2 2 2, 3, 3 3 3 3 3 3 3 3 3, 3, 4, 4 4 4 4 4 4 4 4 4 4 4 4 4 4
& gt; Rep (1:4,each=2,times=1:8,len=3) # use of len, loop complement pay attention to
[1] 1 1 2
> Rep (1:4,each=2,times=3) # after each times
[1] 1 1 2 2 3 3 4 4 1 1 2 2 3 3 4 4 4 1 1 2 2 3 3 3 4 4
> Rep function over!

Reproduced in: https://www.cnblogs.com/business-analysis/p/3414997.html

Read More: