[R] Remove columns by name data[-c("subj","drug")]
Peter Dalgaard BSA
p.dalgaard at pubhealth.ku.dk
Tue Feb 27 10:41:51 CET 2001
"Dieter Menne" <dieter.menne at menne-biomed.de> writes:
> Is there an easy way to remove data frame columns
> by name instead of by index? The following gives
> the idea
>
> remove<-c("subj","drug")
> data[-remove]
>
> I found a solution with a few evals and substitutes,
> similar to that used in reshapeLong, but there must
> be an easier way out.
subset(data, select=-c(subj, drug))
or
remove<-c("subj","drug")
data[-match(remove, names(data))]
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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