Identifying every instance of duplicate ID's with an asterisk

Hi,
I know how to group_by, get_dupes, etc and use str_c to get the asterisk when I only have two duplicate id's but..... when my data frame has multiple duplicate id's I'm stuck. I need an asterisk on all fruits that are only from duplicate id's EXCEPT the last instance. I've inserted sample df and a df_new showing what I require.

Thanks in advance.

#sample dataframes
df <- data.frame (id  = c("375", "400", "600", "600", "600",
                          "850", "850"),
                  name = c("John", "Peter", "Chris", "Chris", "Chris",
                           "Sam", "Sam"),
                  fruit = c("apple", "pear", "banana", "apple",
                            "strawberry", "grape", "apple")
)

df_new <- data.frame (id  = c("375", "400", "600", "600", "600",
                          "850", "850"),
                  name = c("John", "Peter", "Chris", "Chris", "Chris",
                           "Sam", "Sam"),
                  fruit = c("apple", "pear", "banana*", "apple*",
                            "strawberry", "grape*", "apple")
)

What code had you used for that case?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.