Skip to content

Instantly share code, notes, and snippets.

@sjewo
Created August 7, 2014 12:32
Show Gist options
  • Save sjewo/66e0ac703e7143678012 to your computer and use it in GitHub Desktop.
Save sjewo/66e0ac703e7143678012 to your computer and use it in GitHub Desktop.
Select all data.frame columns between two variables
##
## Filename: selectVariableRange.R
## Creation Date: 07-08-2014
## Last Modified: Do 07 Aug 2014 14:21:37 CEST
##
## Description: New Operator to define an vector with
## index numbers of columns between two
## variable names.
##
`%to%` <- function(x,y) {
dat <- as.character(sys.call(1)[2])
grep(x,names(eval(parse(text=dat)))):grep(y,names(eval(parse(text=dat))))
}
# Example
data(iris)
iris[,"Petal.Length"%to%"Species"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment