You can do this with strsplit+ uniquein the instructions lapply:
lapply(mydf, function(x) unique(trimws(unlist(strsplit(x, ",")))))
## $var1
## [1] "a" "b" "x" "d"
##
## $var2
## [1] "a" "b" "s" "m"
##
## $var3
## [1] "a" "c" "d" "s" "e" "m"
##
If you need one line as a result, add there toString, and you can wrap it all in data.frameto get data.frameinstead list:
data.frame(lapply(mydf, function(x) toString(unique(trimws(unlist(strsplit(x, ",")))))))
## var1 var2 var3
## 1 a, b, x, d a, b, s, m a, c, d, s, e, m
, sprintf + paste. , lapply "temp", :
lapply(temp, function(x) sprintf("[%s]", paste(x, collapse = ",")))
#
#
#
#
#
#
#
#
#