Thanks for all your replies. I am using rowsum() and it looks efficient. I
hope I could do some benchmark sometime in near future and let people know.
Or is there any benchmark result available?

On Wed, Aug 31, 2011 at 12:58 PM, Bert Gunter <gunter.ber...@gene.com>wrote:

> Inline below:
>
> On Wed, Aug 31, 2011 at 9:50 AM, Jorge I Velez <jorgeivanve...@gmail.com>
> wrote:
> > Hi Zhenjiang,
> >
> > Try
> >
> > table(unlist(mapply(function(x, y) rep(x, y), y, x)))
>
> Yikes! How about simply tapply(x,y,sum) ??
> ?tapply
>
> -- Bert
> >
> > HTH,
> > Jorge
> >
> >
> > On Wed, Aug 31, 2011 at 12:45 PM, zhenjiang xu <> wrote:
> >
> >> Hi R users,
> >>
> >> suppose I have two vectors,
> >>  > x=c(1,2,3,4,5)
> >>  > y=c('a','b','c','a','c')
> >> How can I get a data.frame like this?
> >> > xy
> >>      count
> >> a     5
> >> b     2
> >> c     8
> >>
> >> I know a few ways to fulfill the task. However, I have a huge number
> >> of this kind calculations, so I'd like an efficient solution. Thanks
> >>
> >> --
> >> Best,
> >> Zhenjiang
> >>
> >> ______________________________________________
> >> R-help@r-project.org mailing list
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>



-- 
Best,
Zhenjiang

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to