Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-03 Thread Rui Barradas
Hello, Either I'm not understanding or isn't this just any of aggregate(count ~ ., data = test, FUN = length) test %>% count(group1, group2, name = "Count") ? Hope this helps, Rui Barradas Às 23:27 de 02/07/21, Yuan Chun Ding escreveu: Hi R users, In this test file, test <- data.frame(

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Yuan Chun Ding
years ago. Ding -Original Message- From: Avi Gross [mailto:avigr...@verizon.net] Sent: Friday, July 2, 2021 5:14 PM To: Yuan Chun Ding ; r-help@r-project.org Subject: RE: [R] add a variable a data frame to sequentially count unique rows Ding, Just to get you to stop asking, here is a soluti

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Bert Gunter
e summary count is below. > count_test <- test %>% group_by(group1 ) %>%summarise(Number_of_region = > n_distinct(group2)) > > Thank you, > > Ding > > -Original Message- > From: Bert Gunter [mailto:bgunter.4...@gmail.com] > Sent: Friday, July 2, 2021 4

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Avi Gross via R-help
7 g2 n6 2 3 8 g2 m103 1 9 g2 m103 2 There are of course other ways to do such things but the above seems simple enough. -Original Message- From: R-help On Behalf Of Yuan Chun Ding Sent: Friday, July 2, 2021 6:27 PM To: r-help@r-project.or

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Yuan Chun Ding
roup_by(group1 ) %>%summarise(Number_of_region > = n_distinct(group2)) > > > Ding > -Original Message- > From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] > Sent: Friday, July 2, 2021 3:36 PM > To: r-help@r-project.org; Yuan Chun Ding ; > r-help@r-project.org

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Yuan Chun Ding
2, 1, 2, 2, 2,3,3 )); I want to get count column. the summary count is below. count_test <- test %>% group_by(group1 ) %>%summarise(Number_of_region = n_distinct(group2)) Thank you, Ding -Original Message- From: Bert Gunter [mailto:bgunter.4...@gmail.c

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Jeff Newmiller
stinct(group2)) Ding -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Friday, July 2, 2021 3:36 PM To: r-help@r-project.org; Yuan Chun Ding ; r-help@r-project.org Subject: Re: [R] add a variable a data frame to sequentially count unique rows It is poor analytical de

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Bert Gunter
Your example makes no sense (to me, anyway). Please check it carefully. Note that the count in rows 2 and 3 increment but the counts in rows 5-7 or rows 8-9 do not. So your specification seems inconsistent to me. Bert Gunter "The trouble with having an open mind is that people keep coming along a

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Yuan Chun Ding
summarise(Number_of_region = n_distinct(group2)) Ding -Original Message- From: Jeff Newmiller [mailto:jdnew...@dcn.davis.ca.us] Sent: Friday, July 2, 2021 3:36 PM To: r-help@r-project.org; Yuan Chun Ding ; r-help@r-project.org Subject: Re: [R] add a variable a data frame to sequentia

Re: [R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Jeff Newmiller
It is poor analytical design to keep duplicates. If they are not duplicates then there should be a distinguishing additional column. IMO you should re-think your analysis rather than accomplish this short-term goal only to find down the road that this duplication causes future problems. On July

[R] add a variable a data frame to sequentially count unique rows

2021-07-02 Thread Yuan Chun Ding
Hi R users, In this test file, test <- data.frame(group1=c("g1", "g1", "g1", "g2", "g2", "g2", "g2", "g2", "g2"), group2=c("k1", "a2", "a2", "c5", "n6", "n6", "n6", "m10","m10"), count= c( 1, 1,2, 1, 2,