I am trying to create a new variable with unique counts of string values from two different columns. So I have something like this, for example:
# A tibble: 4 x
There's another way with toString.
toString
dat$uniquecounts <- sapply(strsplit(apply(dat, 1, toString), ", "), function(x) length(unique(x))) dat # names partners uniquecounts # 1 John Mary, Ashley, John, Kate 4 # 2 Mary Charlie, John, Mary, John 3 # 3 Charlie Kate, Marcy 3 # 4 David Mary, Claire 3