Skip to content

Instantly share code, notes, and snippets.

@yulijia
Created February 18, 2012 03:07
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yulijia/1857130 to your computer and use it in GitHub Desktop.
Save yulijia/1857130 to your computer and use it in GitHub Desktop.
calculate word frequencies with R
sentences<-scan("TEXTname.txt","character",sep="\n");
#Replace full stop and comma
sentences<-gsub("\\.","",sentences)
sentences<-gsub("\\,","",sentences)
#Split sentence
words<-strsplit(sentences," ")
#Calculate word frequencies
words.freq<-table(words);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment