Learn R Programming

gmatrix (version 0.3)

g.rep: Replicate Elements of a vector or gvector,

Description

g.rep replicates the 'vector' or gvector.

Usage

g.rep(x, times = 1L, each = 1L, type = NULL)

Arguments

x
a 'vector' or 'gvector.'
times
a single integer representing the number of times the object should be replicated.
each
a single integer representing the number of times each element should be replicated. If each is specified, the times will be ignored.
type
coerce the output to the given type (i.e "double", "single", "integer" or "logical").

Value

a gvector object with the replicated information

Details

g.rep is somewhat simplified from the R base rep function. It is called g.rep to avoid conflict with the grep function. It can replicate in two different ways. If times is specified then the entire vector is replicated, while when each is specified each element is replicated one at a time.

See Also

rep

Examples

Run this code
x=g.rep(1:2, 2) #returns (1,2,1,2)
x=g.rep(1:2, each=2) #returns (1,1,2,2)

Run the code above in your browser using DataLab