Find all unique values in column separated by comma
Solution 1:
You're almost there, you just need to unlist
before you do the unique
:
all_observers <- unique(unlist(strsplit(as.character(data$observer), ",")))
Solution 2:
We can use separate_rows
on the 'observer', get the distinct
rows, grouped by 'species', and paste
the 'observer'
library(tidyverse)
data %>%
separate_rows(observer) %>%
distinct %>%
group_by(species) %>%
summarise(observer = toString(observer))
Solution 3:
You could also use scan()
unique(scan(text=data$observer, what="", sep=","))
# Read 14 items
# [1] "A" "B" "E" "D" "C" "F"