atom feed5 messages in org.r-project.r-helpRe: [R] subsetting dataframe by rowna...
FromSent OnAttachments
Alexy KhrabrovOct 11, 2008 8:58 pm 
Prof Brian RipleyOct 11, 2008 11:20 pm 
Dieter MenneOct 13, 2008 2:36 am 
Prof Brian RipleyOct 13, 2008 6:01 am 
David WinsemiusOct 13, 2008 12:00 pm 
Subject:Re: [R] subsetting dataframe by rownames to be excluded
From:Prof Brian Ripley (
Date:Oct 13, 2008 6:01:49 am

On Mon, 13 Oct 2008, Dieter Menne wrote:

Prof Brian Ripley <ripley <at>> writes:

Yes: DF[, exclude_me)), ]

Assuming everything is possible in R: would it be possible to make the below work without breaking existing code?

It would be possible, but not I think desirable.

c(exclude) is fine (works now, does nothing useful except strip attributes). But -<char vector> will give an error: that's not necessarily the end, as `[` is a SPECIALSXP and so is passed unevaluated arguments. However, its first step is method dispatch and that evaluates all the arguments, so a substantial internal rewrite would be needed.

It would be fairly easy to make

subset(a, subset=-exclude)

work, and select=-<col_name> already works. I think though that messing with `[` would be too dangerous, and would also lead to expectations that all its methods should accept this notation (and hence many would need to be re-written, including [.data.frame as used here). And then people would expect this to work on RHS, so [<- would need to be re-written ....

a <- data.frame(x=1:10) rownames(a) = letters[1:10] exclude = c("a","c") a[, exclude)), ] # not really that easy to remember

a[-c(1,3),] # In analogy.... a[-c(exclude),] #invalid argument to unary operator