The unary - operator and matrix column labels
Kort, Eric <Eric.Kort at vai.org> writes:
ig1 <- c('patient1', 'patient2')
then, while I can do this:
data[,ig1]
I can no longer do this:
data[,-ig1]
because the unary operator does not like working with column labels. Is
there a way to go backwards and determine the column indices from the column
labels...?
If you know "ig1" is indeed a column of the matrix "data", this should work: R> data[ , -match(ig1, colnames(data))] If you don't know that for sure, and/or you want to preserve the matrix structure of the result (drop=F), then here's a fancier version: R> data[ , setdiff(colnames(data), ig1), drop=F]
-- David Brahm (brahm at alum.mit.edu) -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._