I want to drop columns by name in a matrix, I noticed that it does not work the same as for data frame:
df <- as.matrix(data.frame(x=1:5, y=2:6, z=3:7, u=4:8))
df[ , -which(names(df) %in% c("z","u"))]
df <- data.frame(x=1:5, y=2:6, z=3:7, u=4:8)
df[ , -which(names(df) %in% c("z","u"))]
Why and how can I fix this?