I have a data frame which contains many columns.
I want to create a new data frame which contains only some of the columns, so I've used subset
which works great.
newDF<-subset(oldDF, col1==1)
To complicate things-- I want that one of the columns in the subset will be identified using an interval, such as X
.
For example, I want the new dataFrame to contain all rows from the oldDF
in which the values of Col2Name
are bigger than zero
X <- "colName2"
newDF<-subset(oldDF, X>0)
the problem is that when I run this using X
, I get nothing.
When I run this using the specific column name (and not an interval)
newDF<-subset(oldDF, colName2>0)
I get the right results.
when I test the value in X using oldDF[,X] I get the right column.
What am I missing? what am I doing wrong?