[R] drop unused levels in subset.data.frame

2009-11-10 Thread baptiste auguie
Dear list, subset has a 'drop' argument that I had often mistaken for the one in [.factor which removes unused levels. Clearly it doesn't work that way, as shown below, d - data.frame(x = factor(letters[1:15]), y = factor(LETTERS[1:3])) s - subset(d, y==A, drop=TRUE) str(s) 'data.frame': 5

Re: [R] drop unused levels in subset.data.frame

2009-11-10 Thread David Winsemius
On Nov 10, 2009, at 10:49 AM, baptiste auguie wrote: Dear list, subset has a 'drop' argument that I had often mistaken for the one in [.factor which removes unused levels. Clearly it doesn't work that way, as shown below, d - data.frame(x = factor(letters[1:15]), y = factor(LETTERS[1:3])) s

Re: [R] drop unused levels in subset.data.frame

2009-11-10 Thread Marc Schwartz
On Nov 10, 2009, at 9:49 AM, baptiste auguie wrote: Dear list, subset has a 'drop' argument that I had often mistaken for the one in [.factor which removes unused levels. Clearly it doesn't work that way, as shown below, d - data.frame(x = factor(letters[1:15]), y = factor(LETTERS[1:3])) s -

Re: [R] drop unused levels in subset.data.frame

2009-11-10 Thread baptiste auguie
Neat, I reinvented the wheel! Would that seem like a useful example at the end of the help page for ?subset ? (it currently has very little to say about drop). Thanks also to David for the alternative idea. Best regards, baptiste 2009/11/10 Marc Schwartz marc_schwa...@me.com: On Nov 10,

Re: [R] drop unused levels in subset.data.frame

2009-11-10 Thread Hadley Wickham
If you don't want to preserve factor levels when subsetting use characters. There are very few other differences in behavior. Hadley On Tuesday, November 10, 2009, baptiste auguie baptiste.aug...@googlemail.com wrote: Dear list, subset has a 'drop' argument that I had often mistaken for the