# Define the column and row names:
rownames = c("row1", "row2", "row3", "row4")
colnames = c("col1", "col2", "col3")

# Create the matrix:
P <- matrix(c(3:14),nrow = 4,byrow = TRUE,dimnames = list(rownames,colnames))
P

# Access the element at 3rd column and 1st row:
print("P[1,3]:")
print(P[1,3])

# Access the element at 2nd column and 4th row:
print("P[4,2]:")
print(P[4,2])

# Access only the  2nd row:
print("P[2,1]:")
print(P[2,])

# Access only the 3rd column:
print("P[,3]:")
print(P[,3])

