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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With