I have a list of character vectors in R that represents sets of cooccuring words. From this, I would like to extract a character vector capturing all the words that appear in the list of character vectors. I think I know how to efficiently go from a character vector of words to a unique character vector of the words that appeared. What I don't know how to do is efficiently collapse the list of character vectors into a single character vector. Any tips on how to approach this or the overall problem efficiently would be great appreciated!
+6
A:
Use unlist()
:
> x <- list(l1=c("a","b","c"), l2=c("b","d"))
> unlist(x)
l11 l12 l13 l21 l22
"a" "b" "c" "b" "d"
And to get the unique values, just use unique
:
> unique(unlist(x))
[1] "a" "b" "c" "d"
Shane
2010-02-08 19:24:00
Excellent, thanks Shane!
Chris
2010-02-08 19:37:51