# Matrix Operations

m<-matrix(c(1,2,3,4,5,6,7,8,9,10,11,12), nrow=3, byrow=T)

# Display m

m

# Extract row 3

row3<-m[3,]

# Displau row3

row3

# Extract column 2

col2<-m[,2]

# Display col2

col2

# Insert submatrix into main matrix

m[2:3,1:2]<-matrix(c(1,0,0,1), nrow=2)

# Display m

m

# This can also be done by creating the submatrix first

submatrix<-matrix(c(1,0,0,1), nrow=2)

# Insert submatrix into m

m[2:3,1:2]<-submatrix

# Display m

m

# It could also be done element by element, but this is inefficient

m[2,1]<-1
m[2,2]<-0
m[3,1]<-0
m[3,2]<-1

# Display m

m
