Re: [R] how to create data.frames from vectors with duplicates

2011-09-08 Thread peter dalgaard
On Sep 8, 2011, at 03:18 , zhenjiang xu wrote: > 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? I'm a bit surprised that no-one thought of xtabs

Re: [R] how to create data.frames from vectors with duplicates

2011-09-07 Thread zhenjiang xu
Thanks for benchmarking them. data.table is indeed worth looking at. On Wed, Sep 7, 2011 at 9:55 PM, Dennis Murphy wrote: > Hi: > > Here are a few informal timings on my machine with the following > example. The data.table package is worth investigating, particularly > in problems where its adva

Re: [R] how to create data.frames from vectors with duplicates

2011-09-07 Thread Dennis Murphy
Hi: Here are a few informal timings on my machine with the following example. The data.table package is worth investigating, particularly in problems where its advantages can scale with size. library(data.table) dt <- data.table(x = sample(1:50, 100, replace = TRUE), y = sam

Re: [R] how to create data.frames from vectors with duplicates

2011-09-07 Thread zhenjiang xu
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 wrote: > Inline below: > > On Wed, Aug 31, 2011 at 9:50

Re: [R] how to create data.frames from vectors with duplicates

2011-08-31 Thread William Dunlap
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Bert Gunter > Sent: Wednesday, August 31, 2011 10:10 AM > To: Henrique Dallazuanna > Cc: r-help; zhenjiang xu > Subject: Re: [R] how to create data.frames from vectors with duplicates > > For th

Re: [R] how to create data.frames from vectors with duplicates

2011-08-31 Thread Bert Gunter
For the record, Henrique's use of rowsum() is about 10 times faster than using tapply (and presumably anything with table() ) on my computer. It call a C primitive. -- Bert On Wed, Aug 31, 2011 at 9:55 AM, Henrique Dallazuanna wrote: > Try this: > > rowsum(x, y) > > On Wed, Aug 31, 2011 at 1:45

Re: [R] how to create data.frames from vectors with duplicates

2011-08-31 Thread Bert Gunter
Inline below: On Wed, Aug 31, 2011 at 9:50 AM, Jorge I Velez 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: > >> H

Re: [R] how to create data.frames from vectors with duplicates

2011-08-31 Thread Jorge I Velez
Also tapply(x, y, sum) HTH, Jorge On Wed, Aug 31, 2011 at 12:50 PM, Jorge I Velez <> wrote: > Hi Zhenjiang, > > Try > > table(unlist(mapply(function(x, y) rep(x, y), y, x))) > > HTH, > Jorge > > > On Wed, Aug 31, 2011 at 12:45 PM, zhenjiang xu <> wrote: > >> Hi R users, >> >> suppose I have tw

Re: [R] how to create data.frames from vectors with duplicates

2011-08-31 Thread Marc Schwartz
On Aug 31, 2011, at 11:45 AM, 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

Re: [R] how to create data.frames from vectors with duplicates

2011-08-31 Thread Henrique Dallazuanna
Try this: rowsum(x, y) On Wed, Aug 31, 2011 at 1: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

Re: [R] how to create data.frames from vectors with duplicates

2011-08-31 Thread Jorge I Velez
Hi Zhenjiang, Try table(unlist(mapply(function(x, y) rep(x, y), y, x))) 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 > cou

[R] how to create data.frames from vectors with duplicates

2011-08-31 Thread zhenjiang xu
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. T