Next: replacestr()
Up: MacAnova Help File
Previous: rename()
Contents
Usage:
rep(x, n) or rep(x, repFac), where x is REAL, LOGICAL, or CHARACTER, and
n is an integer > 0 or repFac is a vector of integers >= 0
|
Keywords:
combining variables, variables
Usage
rep(X, n), where n is a positive integer, replicates the values in X n
times to form a vector of length n*length(X). It is equivalent to
vector(X,X,X,...,X), where there are n repetitions of X. X must be a
REAL, LOGICAL or CHARACTER vector, matrix, or array.
rep(X, 0) is legal an has value NULL.
rep(X, Repfac), where Repfac is a vector of integers with length(Repfac)
= length(X) and Repfac[i] >= 0, replicates the j-th element of vector(X)
Repfac[j] times. The result has length length(X)*sum(Repfac). If every
element of Repfac is 0, the result is NULL.
Examples
Examples:
Cmd> rep(vector(1,3,5),4) # same as vector(1,3,5,1,3,5,1,3,5,1,3,5)
(1) 1 3 5 1 3
(6) 5 1 3 5 1
(11) 3 5
Cmd> rep(vector(7,6,5),vector(3,0,2)) # same as vector(7,7,7,5,5)
(1) 7 7 7 5 5
Cmd> a <- factor(rep(run(5),4)); b <- factor(rep(run(4),rep(5,4)))
Cmd> print(a,b) # factors for 4 by 5 factorial design with no reps
a:
(1) 1 2 3 4 5
(6) 1 2 3 4 5
(11) 1 2 3 4 5
(16) 1 2 3 4 5
b:
(1) 1 1 1 1 1
(6) 2 2 2 2 2
(11) 3 3 3 3 3
(16) 4 4 4 4 4
Cmd> rep(run(5), vector(1,2,3))# ERROR! (args have different lengths)
ERROR: in rep(x,m), m must be scalar or a vector the same length as x
Warning
WARNING: Because rep() is a function you cannot use the name 'rep' as a
variable name, say for a replication factor in a design. Use 'Rep' or
'reps' instead.
Cross references
See also topics vector(), run(), 'models', 'glm'.
Gary Oehlert
2006-01-30