How to append specific indices of a matrix in R -
if have matrix:
x <- matrix(c(0), ncol=2, nrow=2)
x [,1] [,2] [1,] 0 0 [2,] 0 0
and want change x[,2][2]
1 instead of 0 , save in new matrix y
output be:
y [,1] [,2] [1,] 0 0 [2,] 0 1
how do in r?
if don't want modify original matrix, reverse order of operations want perform, meaning first store copy of matrix x
in new variable y
, manipulate entries of matrix y
.
y <- x y[2,2] <- 1
else, if want change x
, afterwards store copy of modified matrix in y
... well, guess changes rather obvious: x[2,2] <-1
followed y <- x
.
Comments
Post a Comment