when a column does not exists as a row in a matrix, add a new one as a row of zeros in r
main.r
# Create a matrixmat <- matrix(1:12, nrow = 3, ncol = 4)
# Define the column to be addedcol_to_add <- "5"# Check if the column exists, if not add a new column of zerosif(col_to_add %in% colnames(mat)){
cat("Column already exists")
} else {
mat <- cbind(mat, numeric(nrow(mat)))
colnames(mat)[ncol(mat)] <- col_to_add
}