Re: [R] counting duplicate items that occur in multiple groups

2020-11-18 Thread Tom Woolman
Thanks, everyone! Quoting Jim Lemon : Oops, I sent this to Tom earlier today and forgot to copy to the list: VendorID=rep(paste0("V",1:10),each=5) AcctID=paste0("A",sample(1:5,50,TRUE)) Data<-data.frame(VendorID,AcctID) table(Data) # get multiple vendors for each account

Re: [R] counting duplicate items that occur in multiple groups

2020-11-18 Thread Jim Lemon
Oops, I sent this to Tom earlier today and forgot to copy to the list: VendorID=rep(paste0("V",1:10),each=5) AcctID=paste0("A",sample(1:5,50,TRUE)) Data<-data.frame(VendorID,AcctID) table(Data) # get multiple vendors for each account dupAcctID<-colSums(table(Data)>0) Data$dupAcct<-NA # fill in

Re: [R] counting duplicate items that occur in multiple groups

2020-11-18 Thread Deepayan Sarkar
On Wed, Nov 18, 2020 at 5:40 AM Bert Gunter wrote: > > z <- with(Data2, tapply(Vendor,Account, I)) > n <- vapply(z,length,1) > data.frame (Vendor = unlist(z), >Account = rep(names(z),n), >NumVen = rep(n,n) > ) > > ## which gives: > >Vendor Account NumVen > A1 V1 A1 1 >

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bert Gunter
z <- with(Data2, tapply(Vendor,Account, I)) n <- vapply(z,length,1) data.frame (Vendor = unlist(z), Account = rep(names(z),n), NumVen = rep(n,n) ) ## which gives: Vendor Account NumVen A1 V1 A1 1 A21 V2 A2 3 A22 V3 A2 3 A23 V1 A2

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Avi Gross via R-help
. -Original Message- From: R-help On Behalf Of Tom Woolman Sent: Tuesday, November 17, 2020 6:30 PM To: Bill Dunlap Cc: r-help@r-project.org Subject: Re: [R] counting duplicate items that occur in multiple groups Hi Bill. Sorry to be so obtuse with the example data, I was trying (too hard

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bert Gunter
Why 0's in the data frame? Shouldn't that be 1 (vendor with that account)? Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 17, 2020 at 3:29 PM

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Tom Woolman
Yes, good catch. Thanks Quoting Bert Gunter : Why 0's in the data frame? Shouldn't that be 1 (vendor with that account)? Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County"

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Tom Woolman
Hi Bill. Sorry to be so obtuse with the example data, I was trying (too hard) not to share any actual values so I just created randomized values for my example; of course I should have specified that the random values would not provide the expected problem pattern. I should have just used

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bill Dunlap
What should the result be for Data1 <- data.frame(Vendor=c("V1","V2","V3","V4"), Account=c("A1","A2","A2","A2")) ? Must each vendor have only one account? If not, what should the result be for Data2 <- data.frame(Vendor=c("V1","V2","V3","V1","V4","V2"),

Re: [R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Bert Gunter
Inline. Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Tue, Nov 17, 2020 at 1:20 PM Tom Woolman wrote: > Hi everyone. I have a dataframe that is a

[R] counting duplicate items that occur in multiple groups

2020-11-17 Thread Tom Woolman
Hi everyone. I have a dataframe that is a collection of Vendor IDs plus a bank account number for each vendor. I'm trying to find a way to count the number of duplicate bank accounts that occur in more than one unique Vendor_ID, and then assign the count value for each row in the