Created
August 7, 2014 12:32
-
-
Save sjewo/66e0ac703e7143678012 to your computer and use it in GitHub Desktop.
Select all data.frame columns between two variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
## 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