I have the following data set
df <- data.frame(
path = c(\"a,b,a\",
\"(direct) / (none), (direct) / (none), google / cpc, google / cpc\"
Basic logic behind below code :
i)split each row on "," , (ii) remove whitespace (iii) take unique values
(iv) collapse back on "," and paste
t = apply(df, 1, function(x) paste0(unique(trimws(unlist(strsplit(x,",")))), collapse = ","))
df=data.frame(t)
# df
# t
#1 a,b
#2 (direct) / (none),google / cpc
#3 f,d
#4 a,c