You can create a matrix in R using the matrix() function. Here's an example code that creates a 3x3 matrix:
# Create a matrix
my_matrix <- matrix(1:9, nrow = 3, ncol = 3)
# Print the matrix
print(my_matrix)
Output:
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9