I am trying to subset a data frame using a column names stored in an object. Is this possible? Here is an example:
ReallyLongColNameA <- c(1,2,3,4,5,6)
ReallyLongColNameB <- c(6,5,4,3,2,1)
ReallyLongColNameC <- c(7,8,9,10,11,12)
X <- data.frame(ReallyLongColNameA, ReallyLongColNameB, ReallyLongColNameC)
ReallyLongColA ReallyLongColB ReallyLongColC
1 6 7
You can easily remove the last column by subsetting on column numbers.
You define what rows you want by filtering on the
ShortColNameB, and you define the columns you want by selecting the numbers (e.g. 1st and 2nd column, A & B).