1

i've comma-separeted values like "black,white,black" and i want unique comma separated values:

a <- "black, white, black"

How do I get a unique comma-separated value? Expacted:

res <- "black, white"

Many thanks in advance for your probably very quick answers again.

Axel K
  • 191
  • 8

1 Answers1

4

Try the code below

> toString(unique(unlist(strsplit(a,",\\s+"))))
[1] "black, white"

or

> toString(unique(trimws(scan(text = a, what = character(),sep = ","))))
Read 3 items
[1] "black, white"
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81