If you can live without the subset() function, the tolower() function may work:
dat <- data.frame(XY = 1:5, x = 1:5, mm = 1:5, y = 1:5, z = 1:5, w = 1:5, t = 1:5, r = 1:5) dat[,tolower(names(dat)) %in% c("xy","x")]
However, this will return data.frame with the columns in the order in which they are in the original dat dataset: both
dat[,tolower(names(dat)) %in% c("xy","x")]
and
dat[,tolower(names(dat)) %in% c("x","xy")]
will give the same result, although the order of target names has been reversed.
If you want the columns in the result to be in the order of the destination vector, you need to be a little more bizarre. The following two commands return a data.frame with the columns in the order of the target vector (i.e., the results will be different when the column is on):
dat[,sapply(c("x","xy"),FUN=function(foo)which(foo==tolower(names(dat))))] dat[,sapply(c("xy","x"),FUN=function(foo)which(foo==tolower(names(dat))))]