x <- matrix(1:20, 4,5)
xx <- matrix(0, nrow=dim(x)[2], ncol=dim(x)[2])
xx[upper.tri(xx)] <- x[upper.tri(x)]
xx[lower.tri(xx)] <- x[lower.tri(x, diag=TRUE)]



On Sat, Aug 3, 2013 at 2:54 PM, Martin Batholdy <batholdy@googlemail.com>wrote:

> Hi,
>
> I have a 5 columns x 4 rows matrix and would like to add a diagonal of
> zeros so that I end up with a 5x5 matrix.
>
> x <- matrix(1:20, 4,5)
>
>
> what is the easiest way to accomplish this in R?
>
>
> thanks for any suggestions!
> ______________________________________________
> R-help@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.
>

	[[alternative HTML version deleted]]

