[R] setting up a matrix structure

Erin Hodgess hodgess at gator.dt.uh.edu
Fri Dec 23 19:15:12 CET 2005

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.

Erin Hodgess
Associate Professor
Department of Computer and Mathematical Sciences
University of Houston - Downtown
mailto: hodgess at gator.uhd.edu

More information about the R-help mailing list