I have a column vector that I would like to convert to a diagonal matrix.
That is I have the vector v = (1,2,3) and want to turn it into:
[1, 0, 0]
[0, 2, 0]
[0, 0, 3]
How can I do this in Excel? in R?
I don't care how I do it, I just need to get it done. I know this is a simple question but I've been trying to figure this out for hours now.
(note: my vector is currently in a csv file)
In R
you simply have to do:
> v<- c(1, 2, 3)
> diag(v)
[,1] [,2] [,3]
[1,] 1 0 0
[2,] 0 2 0
[3,] 0 0 3
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With