
Untitled
By: a guest on
May 11th, 2012 | syntax:
None | size: 0.77 KB | hits: 14 | expires: Never
Splitting Strings and Generating Frequency Tables in R
"ABC Industries"
"ABC Enterprises"
"123 and 456 Corporation"
"XYZ Company"
Industries 10
Corporation 31
Enterprise 40
ABC 30
XYZ 40
R> text <- c("ABC Industries", "ABC Enterprises",
+ "123 and 456 Corporation", "XYZ Company")
R> table(do.call(c, lapply(text, function(x) unlist(strsplit(x, " ")))))
123 456 ABC and Company
1 1 2 1 1
Corporation Enterprises Industries XYZ
1 1 1 1
R>
text <- c("ABC Industries", "ABC Enterprises",
"123 and 456 Corporation", "XYZ Company")
table(strsplit(paste(text, collapse=" "), " "))