Re: [R] Quantiles of data in a contingency table

From: Matt Mohebbi <mmohebbi_at_gmail.com>
Date: Sat 19 Mar 2005 - 07:09:52 EST

On Thu, 17 Mar 2005 10:29:16 +0200, Markus Jäntti <markus.jantti@iki.fi> wrote:
> Matt Mohebbi wrote:
> > Hello,
> >
> > I have data of the following form:
> >
> >
> >>data <- data.frame(type=c("c","d","e"), size=c(10,20,30), count=c(20,10,5))
> >>data
> >
> > type size count
> > 1 c 10 20
> > 2 d 20 10
> > 3 e 30 5
> >
> > I would like to compute the quantiles of size given the counts. For
> > instance, in this example, the median size would be 10. Is there an
> > easy way of doing this?
>
> One at least is to the function wtd.median [and wtd.quantile] in package
> Hmisc by Frank Harrell.
>
> install.packages("Hmisc")
> library(Hmisc)
> wtd.median(data$size, data$weights)
>
> is likely a route to get you what you want.
Thanks. This worked great.

I now would like to do a boxplot on a subset of this data. One way of doing this would be to create a repeated entry form of the above data frame. This would look like:

   type size
 1 c 10
 2 c 10
 3 c 10
 4 c 10
 5 c 10
 6 c 10
 7 c 10
 8 c 10
 9 c 10
 10 c 10
 11 c 10
 12 c 10
 13 c 10
 14 c 10
 15 c 10
 16 c 10
 17 c 10
 18 c 10
 19 c 10
 20 c 10
(and similarly for types d and e)

I cannot seem to find this in R or Hmisc. Any ideas?

Thanks,
Matt

> regards,
>
> markus
> >
> > Is there a good way to deal with data in this format in general? Much
> > of R seems to center around having an entry for each item. This
> > question (http://www.r-project.org/nocvs/mail/r-help/2000/0102.html)
> > seems to be related but no one provided an answer.
> >
> > Thanks,
> > Matt
> >
> > ______________________________________________
> > R-help@stat.math.ethz.ch mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> >
>
> --
> Markus Jantti
> Abo Akademi University
> markus.jantti@iki.fi
> http://www.iki.fi/~mjantti
>



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Mar 19 07:14:42 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:51 EST