I have asked a similar question on here before about how to count unique values from a dataframe, but I need to use "lapply" instead because the way I used previously doesn't work or I cant get it to work with a list. I have also been told the using one of the apply functions would be better.
This represents my data:
species1 <- data.frame(var_1 = c("a","a","a","b", "b", "b"), var_2 = c("c","c","d", "d", "e", "e"))
species2 <- data.frame(var_1 = c("f","f","f","g", "g", "g"), var_2 = c("h","h","i", "i", "j", "j"))
all_species <- list()
all_species[["species1"]] <- species1
all_species[["species2"]] <- species2
I want to use lapply to get the number of unique rows for each of my lists, for example, I need an output like:
count_all_species <- list()
count_all_species[["species1"]] <- data.frame(var_1 = c("a", "b"), unique_number = c("2", "2"))
Then the same for the second list using the "lapply" function