Can any body help to write a diagonal matrix A like this in R, please help in this regard
> A [,1] [,2] [,3] [,4] [,5] [,6] [1,] -1 0 0 0 0 0 [2,] 0 -1 0 0 0 0 [3,] 0 0 -1 0 0 0 [4,] 0 0 0 -1 0 0 [5,] 0 0 0 0 -1 0 [6,] 0 0 0 0 0 -1 [7,] 0 0 0 0 0 1 The matrix you have isn't exactly diagonal since it isn't square. However, you can see there's a diagonal matrix in there.
The following code reproduces the matrix
A1 <- diag(-1,6) ## creates a 6x6 diag with -1 on the diag A2 <- c(rep(0,5),1) ## make the bottom row A <- rbind(A1,A2) ## put A1 on top of A2 Then you can see
> A [,1] [,2] [,3] [,4] [,5] [,6] -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 0 0 0 0 0 0 -1 A2 0 0 0 0 0 1