Thursday, May 17, 2007

Repeat elements of a vector

Two methods. The first produces a vector, the second a one column matrix.

x=1:10

# Method 1
rep(x,each=3)

# Method 2
matrix(t(matrix(x,length(x),3)))

No comments: