Charlie Brown
2013-Sep-26 16:24 UTC
[R] help generalizing the following non-symmetric "identity"-like matrix
Hi, I need help generalizing the following non-symmetric "identity"-like matrix In this case: p = 5 k=3 and I want this: I.kp <- cbind(diag(3), c(0, 0, 0), c(0, 0, 0)) How can I generalize this so that I don't have to add/subtract c(0, 0, ... , 0) when p and k changes? Hopefully that makes sense. Thanks. Chuck
William Dunlap
2013-Sep-26 16:31 UTC
[R] help generalizing the following non-symmetric "identity"-like matrix
> p <- 5 > k <- 3 > identical(cbind(diag(3), c(0, 0, 0), c(0, 0, 0)), diag(nrow=k, ncol=p))[1] TRUE Look at help(diag). Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf > Of Charlie Brown > Sent: Thursday, September 26, 2013 9:24 AM > To: R-help > Subject: [R] help generalizing the following non-symmetric "identity"-like matrix > > Hi, > I need help generalizing the following non-symmetric "identity"-like matrix > In this case: > > p = 5 > k=3 > > and I want this: > > I.kp <- cbind(diag(3), c(0, 0, 0), c(0, 0, 0)) > > How can I generalize this so that I don't have to add/subtract c(0, 0, > ... , 0) when p and k changes? > > Hopefully that makes sense. > Thanks. > Chuck > > ______________________________________________ > 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.