Created
July 1, 2013 16:30
-
-
Save atbradley/5902375 to your computer and use it in GitHub Desktop.
Count the number of words in a string. (Via http://stackoverflow.com/questions/8920145/count-the-number-of-words-in-a-string-in-r)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wordcount <- function(str) { | |
sapply(gregexpr("\\b\\W+\\b", str, perl=TRUE), function(x) sum(x>0) ) + 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice function, worked perfect