Giving the following data:
sample <- c(rep("A",5),rep("B",7),rep("C",4),rep("D",9))
species <- sample(x = c("sp1", "sp2","sp3","sp4",NA), size = 25, replace = TRUE)
data <- data.frame(sample,species)
How can I extract the number of unique values in species by sample (A,B,C...)?