I have a dataframe with a list column that was created by str_extract_all(). I'm trying to identify cases where there are more than 1 unique value
#Input =
# List
#1: apple,apple
#2: apple,banana
#3: apple,orange,orange,banana``
dat<-data.table::data.table(
List = list(c("apple","apple"),
c("apple","banana"),
c("apple","orange","orange", "banana")),
Count_Unique = c(1L, 2L, 3L),
Multi = c(FALSE, TRUE, TRUE)
)
I tried dplyr::mutate(Count_Unique = length(unique(List)), but this just gives me the number of unique variables for the entire dataset. I'm sure its very simple I just can't figure how to do this in a rowwise fashion using tidyverse methods if possible.
#Expected Output =
# List Count_Unique Multi
#1: apple,apple 1 FALSE
#2: apple,banana 2 TRUE
#3: apple,orange,orange,banana 3 TRUE
dat<-data.table::data.table(
List = list(c("apple","apple"),
c("apple","banana"),
c("apple","orange","orange", "banana")),
Count_Unique = c(1L, 2L, 3L),
Multi = c(FALSE, TRUE, TRUE)
)
question from:https://stackoverflow.com/questions/66056193/count-unique-in-each-list-column