Search code examples
rlisttm

How to select repeated words in an R column as a list


I have a dataframe

 DF<- slNo names  
       1      get
       2      free
       3      new
       4      get
       5      new

I want to obtain a list of the words used in the names column

  list<- c(get, free, new)

I can use tm package to create a term document matrix for this but that seems long and awakward. is there a simpler more elagant way to achieve this


Solution

  • We can use unique to get a vector of set of 'names'

    v1 <- unique(DF$names)
    v1
    #[1] "get"  "free" "new" 
    

    if we need to store is a list

    lst <- as.list(unique(DF$names))