Re: [R] subset(..., drop=TRUE) doesn't seem to work.

About this list Date view Thread view Subject view Author view Attachment view

From: Prof Brian Ripley (ripley@stats.ox.ac.uk)
Date: Thu 17 Jun 2004 - 02:04:42 EST


Message-id: <Pine.LNX.4.44.0406161659040.14482-100000@gannet.stats>

On Wed, 16 Jun 2004, Paul Lemmens wrote:

> Dear Peter,
>
> --On woensdag 16 juni 2004 17:06 +0200 Peter Dalgaard
> <p.dalgaard@biostat.ku.dk> wrote:
>
> > Paul Lemmens <P.Lemmens@nici.kun.nl> writes:
> >
> >> Hello!
> >>
> >> If I read ?subset, the workings of the argument drop (to me) seem to
> >> imply equivalence of A and B (R 1.9.0):
> >>
> >> # A
> >> dd <- data.frame(rt=rnorm(10), c=factor(gl(2,5)))
> >> dd <- subset(dd, c==1)
> >> dd$c <- dd$c[, drop=TRUE]
> >> table(dd$c)
> >>
> >> 1
> >> 5
> >>
> >>
> >> # B
> >> dd <- data.frame(rt=rnorm(10), c=factor(gl(2,5)))
> >> dd <- subset(dd, c==1, drop=TRUE)
> >> table(dd$c)
> >>
> >> 1 2
> >> 5 0
> >>
> >> So to lose the second level of dd$c, in method B I still need to 'dd$c
> >> <-
> >> dd$c[, drop=TRUE]', while the manual seems to imply that with the drop
> >> argument to subset() this would not be necessary.
> >>
> >>
> >> Could you comment?
> >
> > Looks like a documentation bug. The actual code ends up doing
> >
> > x[r, vars, drop = drop]
> >
> > and "[.data.frame" will not drop factor levels. I wonder if it ever
> > did...

No, AFAIK. It was definitely not documented to last November when that
comment was added to ?subset.

> Bottomline: unless I find the time to submit a patch for '[.data.frame',
> I'll need to use the more elaborate way of dropping the unused levels?
>
> Does "will not drop" imply that it cannot be programmed, should not be
> programmed, or has not been programmed yet?

It is designed not to. Look at how ?"[.data.frame" documents it. We
don't want it altered and it would break a lot of code to do so. I think
the author of those lines was under a misapprension.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ R-help@stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


About this list Date view Thread view Subject view Author view Attachment view

This archive was generated by hypermail 2.1.3 : Wed 30 Jun 2004 - 23:05:08 EST