To understand what a matrix is and how to create a matrix in R, read this shot.
To remove the row(s) and column(s) of a current matrix in R, we use the c()
function.
c()
functionThe numbers that represent the row number and column number we wish to remove are the parameters. For example:
[-c(1), -c(1)]
The code above specifies the first row and the first column.
mymatrix <- matrix(c("apple", "banana", "cherry", "orange", "mango", "pineapple"), nrow = 3, ncol =2)# removing the first row an first colummn of the matrixmymatrix <- mymatrix[-c(1), -c(1)]mymatrix
mymatrix
. We use the matrix()
function and pass the parameter values of its shape. nrow = 3
represents 3 rows, while ncol = 2
represents 2 columns.c()
function, we remove the first row and first column [-c(1), -c(1)]
from the matrix.