[R] Generating a sequence of diagonal matrices
Joshua Wiley
jwiley.psych at gmail.com
Tue Aug 30 22:23:36 CEST 2011
Hi Meddee,
Try this:
dmat <- lapply(1:100, function(d) diag(d, 2))
That will give you a list of all 100 matrices.
Cheers,
Josh
On Tue, Aug 30, 2011 at 1:00 PM, meddee <meddee1000 at gmail.com> wrote:
> I am trying to generate a sequence of diagonal matrices.
>
> In the scalar case I would use something like, seq(0,100,by=1).
>
> How do I generalise the above for , say a 2 dimensional diagonal matrix. In
> other words how do I produce the series of diagonal matrices {
> diag(0,2),diag(1,2), diag(2,2),...,diag(100,2)}?
>
> Thanks
> Meddee
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Generating-a-sequence-of-diagonal-matrices-tp3779623p3779623.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/
More information about the R-help
mailing list