saving . . . saved MATRICES- Creating 3 X 3 IDENTITY MATRIX has been deleted. MATRICES- Creating 3 X 3 IDENTITY MATRIX has been hidden .
MATRICES- Creating 3 X 3 IDENTITY MATRIX
Question
I have encountered a problem in creating 3 x 3 identity matrix.
#create a matrix of 3 rows and 3 columns using the following code

values <- c(1,0,0,0,1,0,0,0,1)
matrixB <- as.matrix(values, nrow = 3, ncol = 3, byrow = TRUE)
print(matrixB)

But output i am getting is
print(matrixB)
[,1]
[1,]    1
[2,]    0
[3,]    0
[4,]    0
[5,]    1
[6,]    0
[7,]    0
[8,]    0
[9,]    1

Thanks.

R Creating-Matrices-using-Data-Frames 06-07 min 30-40 sec 02-04-20, 6:05 p.m. annieahuja89@gmail.com

Please review your second line of code. You should not use as.matrix function, rather you should use matrix function as given below:
matrixB <- matrix(values, nrow = 3, ncol = 3, byrow = TRUE)

02-04-20, 11:49 p.m. sudhakarst
Thank you for the response
02-04-20, 11:53 p.m. annieahuja89@gmail.com

We should not use dot matrix function. Wrong line of code=>  <span style="background-color: rgb(250, 250, 250);">matrixB <- as.matrix(values, nrow = 3, ncol = 3, byrow = TRUE)                   </span>
<span style="background-color: rgb(250, 250, 250);"> Use    </span>matrixB<-matrix(values,nrow = 3,ncol = 3, byrow = TRUE)
Hint:   as.matrix => used for creating matrix from dataset

<span style="background-color: rgb(250, 250, 250);">
</span>
<span style="background-color: rgb(250, 250, 250);">
</span>
21-04-20, 4:14 p.m. rdevi.lit@gmail.com

28-04-20, 2:53 p.m. angaiaruvi@gmail.com

codevalues <- c(1,0,0,0,1,0,0,0,1)
matrixB <- matrix(codevalues, nrow = 3, ncol = 3, byrow = TRUE)
print(matrixB)
28-04-20, 2:54 p.m. angaiaruvi@gmail.com