I want to count the number of unique values ββfor each row.
For example, with this data frame:
example <- data.frame(var1 = c(2,3,3,2,4,5), var2 = c(2,3,5,4,2,5), var3 = c(3,3,4,3,4,5))
I want to add a column that counts the number of unique values ββfor each row; for example, 2 for the first row (since the first row is 2 and 3) and 1 for the second row (since there are only 3 in the second row).
Does anyone know a simple code for this? So far, I have found code to count the number of unique values ββfor each column.
source share