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:
dl> td> tr> | times code> td>
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:
- R language notes – sample() function
- Solving the problem of saving object set by save() function in R language
- Error debug in box2d createfixture Error:R6025 pure Virtual function call solution
- error: ‘CLOCK_MONOTONIC‘ undeclared (first use in this function)
- Installation and use of R language ggmap package
- How to Use the Reverse() Function
- There will be row spacing problems in algorithm use in latex. Please use the ‘setstretch {1.35}
- How to use C + + function pointer array
- error: invalid use of non-static member function
- use cv.imshow Error: (- 215: assertion failed) size.width >0 && size.height >0 in function ‘cv::imshow’
- [Mac OS] ASUS z97-k r2.0 + gtx960 + clover v2.4k r4098 install Sierra 10.12.5 problems and Solutions
- The use of C + + template function and lambda expression
- The solution of “error in NLS loop more than 50” in R language
- nvalid default value for prop “params“: Props with type Object/Array must use a factory function to
- How to use Python split() function (split array)
- The reason of error in R file
- Usage and examples of three important functions of tidyr package in R language: gather, spread and separate
- Renaming the column name of data frame in R language
- 【R】【unimplemented type ‘list’ in ‘orderVector1’】
- R-DataCamp-Data Manipulation with dplyr in R