[R] How to generate a matrix where each row (or column) is the same vector?
Romain Francois
romain.francois at dbmail.com
Thu Sep 17 16:14:00 CEST 2009
On 09/17/2009 04:02 PM, Peng Yu wrote:
>
> Hi,
>
> I can use the following code to generate a matrix, each column of
> which is 'x'. But I have to specify '5' twice in the second command. I
> am wondering if there is a better way to do it.
>
>> x=1:10
>> matrix(rep(x,5),nc=5)
>> t(matrix(rep(x,5),nc=5))
>
> Regards,
> Peng
Or this ;
> matrix(rep(x,5),nr=length(x))
Romain
--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/yw8E : New R package : sos
|- http://tr.im/y8y0 : search the graph gallery from R
`- http://tr.im/y8wY : new R package : ant
More information about the R-help
mailing list