Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 11th, 2012  |  syntax: None  |  size: 0.77 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Splitting Strings and Generating Frequency Tables in R
  2. "ABC Industries"  
  3. "ABC Enterprises"  
  4. "123 and 456 Corporation"  
  5. "XYZ Company"
  6.        
  7. Industries   10  
  8. Corporation  31  
  9. Enterprise   40  
  10. ABC          30  
  11. XYZ          40
  12.        
  13. R> text <- c("ABC Industries", "ABC Enterprises",
  14. +            "123 and 456 Corporation", "XYZ Company")
  15. R> table(do.call(c, lapply(text, function(x) unlist(strsplit(x, " ")))))
  16.  
  17.         123         456         ABC         and     Company
  18.           1           1           2           1           1
  19. Corporation Enterprises  Industries         XYZ
  20.           1           1           1           1
  21. R>
  22.        
  23. text <- c("ABC Industries", "ABC Enterprises",
  24.          "123 and 456 Corporation", "XYZ Company")
  25.  
  26. table(strsplit(paste(text, collapse=" "), " "))