Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R. how to make matrix which have equal rows

Tags:

r

I have row f. I want create matrix R such that every row of it is equal f. What is the most efficient way to do it in R?

like image 426
ashim Avatar asked Jun 03 '12 01:06

ashim


1 Answers

with a row

f=c(1,22,33,44,55,66)

get its length

lf=length(f)

Then make the matrix

R=matrix(rep(f,lf),
         ncol=lf,
         byrow=T)

Gives:

R
     [,1] [,2] [,3] [,4] [,5]
[1,]    1   33   44   55   66
[2,]    1   33   44   55   66
[3,]    1   33   44   55   66
[4,]    1   33   44   55   66
[5,]    1   33   44   55   66
like image 161
Seth Avatar answered Sep 21 '22 08:09

Seth