I have a dataframe similar to the one below and I need to count how many times the same row pattern repeats in this data frame.
start_id | end_id | type | id
1 | 2 | a | 1
2 | 5 | a | 2
1 | 3 | b | 3
2 | 5 | a | 4
1 | 3 | b | 5
The result I want is this:
start_id | end_id | type | n
1 | 2 | a | 1
2 | 5 | a | 2
1 | 3 | b | 2
I tried the following code, but it is not merging the records, it is returning the same rows as they are, just adding a new column with the counter, which is bad for my analysis:
Sumary <- clear_filt_trip %>%
group_by(start_id, end_id, type) %>%
add_count(across(everything()))
I tried using summarize
but it's just repeating the columns.
What can I do about it?