1

I have a list of words

a = c("when","to","use","each","effect","","recognizing","each","effect","?",":")
a
[1] "when"        "to"          "use"         "each"       
[5] "effect"      ""            "recognizing" "each"       
[9] "effect"      "?"           ":" 

This list could have contained thousands of words. How can I effectively find out the unique words, i.e. "when" "to" "use" "each" "effect" "recognizing"?

I am trying to avoid for loops whenever possible.

Thanks

wen
  • 1,875
  • 4
  • 26
  • 43

2 Answers2

2
unique(a)

You might also like

table(a)
JeremyS
  • 3,497
  • 1
  • 17
  • 19
  • Thanks, I was searching online for like a hour. Didn't know it's this easy! – wen Feb 07 '14 at 08:33
  • First thing to try is type `?unique` (or whatever) into R, if that comes up empty then `??unique`, if that comes up empty then web search. – JeremyS Feb 07 '14 at 08:36
-1

You can use a hashmap to maintain the list instead of using an array. It would automatically maintain the uniqueness of your data.

Saket
  • 124
  • 9