Question

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

Was it helpful?

Solution

unique(a)

You might also like

table(a)

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top