I'm trying to summarise a dataframe by ID but I would like to summarise only when the same ID repeats in two rows and not summarise when the same ID repeats in more than two rows. I have tried:
df %>% group_by(ID) %>% dplyr::summarize_if(n() == 2, first)
,
but Im getting an error says: "Error in n()
:
! Must be used inside dplyr verbs."
tnx for helping!