We can use the following to specify which columns to select by names.
z[, c(“a”, “b”)]
This also works.
z[c(“a”, “b”)]
Or we can use the following to first specify which columns to remove in a vector, and then select the columns not in that vector.
cols_remove <- c("c", "d")
z[, !(colnames(z) %in% cols_remove)]