Adding elements to the diagonal of a matrix that is not square in R -
i want able add value (in code nug
) i,j entry of matrix = j (so kronecker delta function). easy when matrix square (see code below) not sure how in 1 line when matrix not square
nug = 2 r = tau + diag(nug,nrow(tau))
the above code works when tau square matrix imagine tau
not square. how add nug
each of i,j elements of tau
= j?
m <- matrix(1:6, ncol = 2) m [,1] [,2] [1,] 1 4 [2,] 2 5 [3,] 3 6 diag(m) <- diag(m) + 1:2 m [,1] [,2] [1,] 2 4 [2,] 2 7 [3,] 3 6
Comments
Post a Comment