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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -