The document discusses creating and manipulating vectors and matrices in R. It shows how to create matrices using the matrix() function and assign row and column names using dimnames(). It demonstrates accessing and modifying matrix elements, adding rows and columns, and performing basic arithmetic operations like addition, subtraction, multiplication and division on matrices.
The document discusses creating and manipulating vectors and matrices in R. It shows how to create matrices using the matrix() function and assign row and column names using dimnames(). It demonstrates accessing and modifying matrix elements, adding rows and columns, and performing basic arithmetic operations like addition, subtraction, multiplication and division on matrices.
The document discusses creating and manipulating vectors and matrices in R. It shows how to create matrices using the matrix() function and assign row and column names using dimnames(). It demonstrates accessing and modifying matrix elements, adding rows and columns, and performing basic arithmetic operations like addition, subtraction, multiplication and division on matrices.
The document discusses creating and manipulating vectors and matrices in R. It shows how to create matrices using the matrix() function and assign row and column names using dimnames(). It demonstrates accessing and modifying matrix elements, adding rows and columns, and performing basic arithmetic operations like addition, subtraction, multiplication and division on matrices.
print(P) Q <- matrix(c(3:14), nrow = 4, byrow = FALSE) print(Q) #assigning row names and column names rownames=c("row1","row2","row3","row4") colnames=c("col1","col2","col3") dimnames(P)=list(rownames,colnames) print(P) #accessing element from matrix P[1,3] Q[1,] P[,3] #modification of matrix-assigning a single element P[2,2]=20 print(P) #modification of matrix-modifying multiple elements Q[Q>=11]=0 print(Q) #modification of matrix-addition of rows P=rbind(P,c(17,18,19)) print(P) #modification of matrix-addition of columns Q=cbind(Q,c(20,21,22,23)) Q #matrix operations R=matrix(c(1:16),4,4) R #addition a=R+Q a #Subtraction b=R-Q b #Multiplication c=R*Q c #Division d=R/Q d #Multiplication by constant e=R*5 e
OUTPUT: RESULT: Thus the program was completed and the output was verified successfully.