Skip to content
Prev 274345 / 398506 Next

delete columns which partially match expression

Be careful with the idiom
   x[, -which(columnIsBad)]
If no columns are bad this leads to
   x[, -integer(0)]
which is a data.rame with no columns,
exactly the opposite of what you want.
   x[, !columnIsBad]
doesn't have that problem.  However, if
you can't tell if a column is bad or not
(i.e., columnIsBad contains an NA) you
will have to process columnIsBad to turn
that NA into a definite TRUE or FALSE.

Finally, add the drop=FALSE argument to []
in case the result would be a one-column
data.frame to prevent it from being converted
to the column itself.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com