R summarize unique values across columns based on values from one column
问题 I want to know the total number of unique values for each column based on the values of var_1. For example: Test <- data.frame(var_1 = c("a","a","a", "b", "b", "c", "c", "c", "c", "c"), var_2 = c("bl","bf","bl", "bl","bf","bl","bl","bf","bc", "bg" ), var_3 = c("cf","cf","eg", "cf","cf","eg","cf","dr","eg","fg")) The results I am looking for would be based on the values in var_1 and should be: var_1 var_2 var_3 a 2 2 b 2 1 c 3 4 However, after trying various methods (including apply and table)