Skip to content
Prev 388438 / 398502 Next

add a variable a data frame to sequentially count unique rows

Hi Jeff,

Thank you for your quick response!!
I made this following summary file, however, I want to add the count number sequentially into the original file, because I have several more columns to explain or annotate the first two columns.

count_test <- test %>% group_by(group1 ) %>%summarise(Number_of_region = n_distinct(group2))


Ding
-----Original Message-----
From: Jeff Newmiller [mailto:jdnewmil at dcn.davis.ca.us] 
Sent: Friday, July 2, 2021 3:36 PM
To: r-help at r-project.org; Yuan Chun Ding <ycding at coh.org>; r-help at r-project.org
Subject: Re: [R] add a variable a data frame to sequentially count unique rows

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 2, 2021 3:27:21 PM PDT, Yuan Chun Ding <ycding at coh.org> wrote:
--
Sent from my phone. Please excuse my brevity.