This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
source("supportFunctions.R")
# Specific Conditions and Boundaries
text <- whichTextF(c(79273038,53332248))
seed <- getMySeed(c(79273038,53332248))
options <- whichCharacterOption(c(79273038,53332248))
set.seed(seed)
library(tm)
## Loading required package: NLP
library(ggplot2)
##
## Attaching package: 'ggplot2'
## The following object is masked from 'package:NLP':
##
## annotate
library(wordcloud)
## Loading required package: RColorBrewer
lines <- readLines(text)
fullt <- paste(lines, collapse = '')
str(fullt)
## chr "My fellow Americans:Three days from now, after half a century in the service of our country, I shall lay down the responsibilit"| __truncated__
charArray <- strsplit(fullt, "")
freqTable <- table(charArray)
# First Part - 1
sortedArray <- sort(freqTable, decreasing=TRUE)
table <- data.frame(word=names(sortedArray),freq=sortedArray)
# First Part - 2
result <- ggplot(data=table,aes(y=sortedArray,x=names(sortedArray))) + geom_bar(stat="identity") + coord_flip()
# First Part - 3
array <- unlist(charArray)
numero <- length(array)
# First Part - 4
toRemove <- c(".", ",", ";", ":", "!", "-", "?")
unlistedArray <- unlist(charArray)
newArray <- c()
for(character in array){
if(!character %in% toRemove){
newArray <- append(newArray, character, after=length(newArray))
}
}
length(unlistedArray)
## [1] 11102
length(newArray)
## [1] 10851
# First Part - 5
# There're similiar number of characters and signs of punctuation.
# The most used sign is the blank space and the most used character is the "e" letter.
# Second Part (Before Specific Text Mining Task) - 1
length(lines)
## [1] 47
mytext <- read.table(text,stringsAsFactors = FALSE,sep="\n")
# Second Part (Before Specific Text Mining Task) - 2
wordList<-strsplit(fullt, "\\W+") # Identify words throught whitespace
# The regular expression symbol \\W to match non-word characters, using + to indicate one or more in a row
str(wordList)
## List of 1
## $ : chr [1:1852] "My" "fellow" "Americans" "Three" ...
wordVect<-unlist(wordList) # convert the list to a vector
length(wordVect)
## [1] 1852
# Second Part (Before Specific Text Mining Task) - 3
for(line in lines){
wordList<-strsplit(line, "\\W+") # Identify words throught whitespace
# The regular expression symbol \\W to match non-word characters, using + to indicate one or more in a row
str(wordList)
vect<-unlist(wordList) # convert the list to a vector
print(length(vect))
}
## List of 1
## $ : chr [1:3] "My" "fellow" "Americans"
## [1] 3
## List of 1
## $ : chr(0)
## [1] 0
## List of 1
## $ : chr [1:38] "Three" "days" "from" "now" ...
## [1] 38
## List of 1
## $ : chr [1:25] "This" "evening" "I" "come" ...
## [1] 25
## List of 1
## $ : chr [1:32] "Like" "every" "other" "citizen" ...
## [1] 32
## List of 1
## $ : chr(0)
## [1] 0
## List of 1
## $ : chr [1:30] "Our" "people" "expect" "their" ...
## [1] 30
## List of 1
## $ : chr [1:52] "My" "own" "relations" "with" ...
## [1] 52
## List of 1
## $ : chr [1:64] "In" "this" "final" "relationship" ...
## [1] 64
## List of 1
## $ : chr(0)
## [1] 0
## List of 1
## $ : chr "II"
## [1] 1
## List of 1
## $ : chr [1:88] "We" "now" "stand" "ten" ...
## [1] 88
## List of 1
## $ : chr "III"
## [1] 1
## List of 1
## $ : chr [1:72] "Throughout" "America" "s" "adventure" ...
## [1] 72
## List of 1
## $ : chr [1:115] "Progress" "toward" "these" "noble" ...
## [1] 115
## List of 1
## $ : chr [1:89] "Crises" "there" "will" "continue" ...
## [1] 89
## List of 1
## $ : chr [1:92] "But" "each" "proposal" "must" ...
## [1] 92
## List of 1
## $ : chr [1:47] "The" "record" "of" "many" ...
## [1] 47
## List of 1
## $ : chr "IV"
## [1] 1
## List of 1
## $ : chr [1:33] "A" "vital" "element" "in" ...
## [1] 33
## List of 1
## $ : chr [1:30] "Our" "military" "organization" "today" ...
## [1] 30
## List of 1
## $ : chr [1:87] "Until" "the" "latest" "of" ...
## [1] 87
## List of 1
## $ : chr [1:73] "This" "conjunction" "of" "an" ...
## [1] 73
## List of 1
## $ : chr [1:36] "In" "the" "councils" "of" ...
## [1] 36
## List of 1
## $ : chr [1:54] "We" "must" "never" "let" ...
## [1] 54
## List of 1
## $ : chr [1:22] "Akin" "to" "and" "largely" ...
## [1] 22
## List of 1
## $ : chr [1:31] "In" "this" "revolution" "research" ...
## [1] 31
## List of 1
## $ : chr [1:76] "Today" "the" "solitary" "inventor" ...
## [1] 76
## List of 1
## $ : chr [1:28] "The" "prospect" "of" "domination" ...
## [1] 28
## List of 1
## $ : chr [1:36] "Yet" "in" "holding" "scientific" ...
## [1] 36
## List of 1
## $ : chr [1:37] "It" "is" "the" "task" ...
## [1] 37
## List of 1
## $ : chr(0)
## [1] 0
## List of 1
## $ : chr "V"
## [1] 1
## List of 1
## $ : chr [1:83] "Another" "factor" "in" "maintaining" ...
## [1] 83
## List of 1
## $ : chr(0)
## [1] 0
## List of 1
## $ : chr "VI"
## [1] 1
## List of 1
## $ : chr [1:42] "Down" "the" "long" "lane" ...
## [1] 42
## List of 1
## $ : chr [1:52] "Such" "a" "confederation" "must" ...
## [1] 52
## List of 1
## $ : chr [1:103] "Disarmament" "with" "mutual" "honor" ...
## [1] 103
## List of 1
## $ : chr [1:47] "Happily" "I" "can" "say" ...
## [1] 47
## List of 1
## $ : chr(0)
## [1] 0
## List of 1
## $ : chr "VII"
## [1] 1
## List of 1
## $ : chr [1:58] "So" "in" "this" "my" ...
## [1] 58
## List of 1
## $ : chr [1:49] "You" "and" "I" "my" ...
## [1] 49
## List of 1
## $ : chr [1:19] "To" "all" "the" "peoples" ...
## [1] 19
## List of 1
## $ : chr [1:109] "We" "pray" "that" "peoples" ...
## [1] 109
## List of 1
## $ : chr(0)
## [1] 0
# Second Part (Before Specific Text Mining Task) - 4
# Second Part (Before Specific Text Mining Task) - 5
# words are longer in the middle
# Second Part (Text mining) - 1
wordList<-strsplit(fullt, "\\W+") # Identify words throught whitespace
wordVect<-unlist(wordList)
wordFreq <- table(wordVect)
sortedWords <- sort(wordFreq, decreasing=TRUE)
# Second Part (Text mining) - 2
tablenames <- data.frame(word=names(sortedWords),freq=sortedWords)
ggplot(data=tablenames,aes(y=sortedWords,x=names(sortedWords))) + geom_bar(stat="identity") + coord_flip()
# Second Part (Text mining) - 3
library(wordcloud)
dfw <- data.frame(word=names(sortedWords),freq=sortedWords)
wordcloud(dfw$word,dfw$freq,min.freq=2,max.words=100, random.order=T, rot.per=0.35,colors=brewer.pal(8, "Dark2"))
# Second Part (Text mining) - 4
#The number of lines is the same as the paragraphs.
# Second Part (Text mining) - 5
#The most used words are the article the and the prepositons and, of, in ...