Skip to content

Instantly share code, notes, and snippets.

@natbusa
Last active August 29, 2015 13:57
Show Gist options
  • Save natbusa/9644502 to your computer and use it in GitHub Desktop.
Save natbusa/9644502 to your computer and use it in GitHub Desktop.
Word count in R
#read in and clean
x = scan("lorem.txt", what="", sep=" ")
x.clean = gsub("\\W+","",tolower(x))
#word count
wc = table(x.clean)
#output to stdout
print(as.data.frame(wc), row.names=rep("", nrow(wc)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment