[R] Removing columns from data frame
Tony Plate
tplate at blackmesacapital.com
Tue Jul 23 01:29:10 CEST 2002
The answer to your question is probably "No".
You could do
x[,is.na(match(names(x), c("unwanted column names"))),drop=F]
or
x[ ,-match(names(x), c("unwanted column names"), nomatch=0),drop=F]
While
x[,!(names(x) %in% c("unwanted column names")),drop=F]
is a few characters shorter, but you said you don't want to do that... (why
is that?)
-- Tony Plate
At 02:13 PM 7/22/2002 -0300, you wrote:
>Hello,
>
>Is there an easy way to remove a few columns from a data frame by
>indicating the column names? I am thinking of an operator like the "-" to
>remove the columns when referenced by column number, and I don't want to
>use the %in% operator together with the names() function.
>
>Thanks
>Daniel Mastropietro
>
>-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
>r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
>Send "info", "help", or "[un]subscribe"
>(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
>_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list