Re: [R] setting up a matrix structure

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Sat 24 Dec 2005 - 05:26:17 EST

Try this:

n <- 3; m <- 2 # test values
kronecker(diag(n), matrix(1, 1, m))

On 12/23/05, Erin Hodgess <hodgess@gator.dt.uh.edu> wrote:
> Dear R People:
>
> I have an n x (nm) matrix.
>
> In the first row, there will be n ones, followed by n(m-1) zeros.
> In the second row, there will be n zeros, n ones, and the rest zeros.
> In the third row, 2n zeros, n 1 and the rest zeros.
> .
> .
> .
> In the nth row, n(m-1) zeros and n ones.
>
> My question: how can I do this elegantly and efficiently, please?
>
> A loop will work just fine, but there must be a better way, please.
>
> Thanks for any help!
>
> R Version 2.2.0, Windows.
>
> Sincerely,
> Erin Hodgess
> Associate Professor
> Department of Computer and Mathematical Sciences
> University of Houston - Downtown
> mailto: hodgess@gator.uhd.edu
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Dec 24 05:33:18 2005

This archive was generated by hypermail 2.1.8 : Sat 24 Dec 2005 - 09:30:07 EST