[R] help generalizing the following non-symmetric "identity"-like matrix

William Dunlap wdunlap at tibco.com
Thu Sep 26 18:31:34 CEST 2013


> 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.



More information about the R-help mailing list