Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

My Homework #28

Merged
merged 2 commits into from
Oct 26, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Homework October 18th
  • Loading branch information
christophguemmer committed Oct 18, 2016
commit c1ae3ca863b76e72a452136f5e273e13f8b84612
21 changes: 21 additions & 0 deletions Guemmer_Christoph/18_10/Austen.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
text.v <- scan("R/TextAnalysisWithR/data/plainText/austen.txt", what="character", sep="\n")
start.v <- which(text.v=="CHAPTER 1")
end.v <- which(text.v=="THE END")
start.meta.v <- text.v[1:start.v -1]
end.meta.v <- text.v[(end.v+1) :length(text.v)]
metadata.v <- c(start.meta.v, end.meta.v)
novel.lines.v <- text.v[start.v:end.v]
novel.v <- paste(novel.lines.v, collapse=" ")
novel.lower.v <- tolower(novel.v)
austen.words.l <- strsplit(novel.lower.v, "\\W")
austen.word.v <- unlist(austen.words.l)
not.blanks.v <- austen.word.v[which(austen.word.v!="")]
austen.freqs.t <- table(not.blanks.v)
sorted.austen.freqs.t <- sort(austen.freqs.t, decreasing=TRUE)
most.freq.v <- sorted.austen.freqs.t[1:10]
plot(most.freq.v, xlab="Words", ylab="Total Frequency in the Book")
sorted.austen.rel.freqs.t <- 100*(sorted.austen.freqs.t/sum(sorted.austen.freqs.t))
rel.most.freq.v <- sorted.austen.rel.freqs.t[1:10]
plot(rel.most.freq.v, type="b", xlab="Top Ten Words", ylab="Percentage of Full Text", xaxt ="n")
axis(1,1:10, labels=names(sorted.austen.rel.freqs.t [1:10]))
most.freq.words.v <- c("to", "the", "of", "and", "her", "i", "in", "a", "was", "it", "his", "that")
Binary file not shown.
Binary file not shown.
21 changes: 21 additions & 0 deletions Guemmer_Christoph/18_10/JockerChapter2.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
text.v <- scan("R/TextAnalysisWithR/data/plainText/melville.txt", what ="character", sep ="\n")
text.v
text.v[1]
start.v <- which(text.v == "CHAPTER 1. Loomings.")
end.v <- which(text.v == "orphan.")
start.metadata.v <- text.v[1:start.v -1]
end.metadata.v <- text.v[(end.v+1):length(text.v)]
metadata.v <- c(start.metadata.v, end.metadata.v)
novel.lines.v <- text.v[start.v:end.v]
novel.v <- paste(novel.lines.v, collapse=" ")
novel.lower.v <- tolower(novel.v)
moby.words.l <- strsplit(novel.lower.v, "\\W")
str(moby.words.l)
moby.word.v <- unlist(moby.words.l)
not.blanks.v <- which(moby.word.v!="")
moby.word.v <- moby.word.v[not.blanks.v]
length(moby.word.v[which(moby.word.v=="whale")])
whale.hits.v <- length(moby.word.v[which(moby.word.v=="whale")])
total.words.v <- length(moby.word.v)
moby.freqs.t <- table(moby.word.v)
sorted.moby.freqs.t <- sort(moby.freqs.t, decreasing =TRUE)
20 changes: 20 additions & 0 deletions Guemmer_Christoph/18_10/JockersChapter3.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
text.v <- scan("R/TextAnalysisWithR/data/plainText/melville.txt", what="character", sep="\n")
start.v <- which(text.v == "CHAPTER 1. Loomings.")
end.v <- which(text.v == "orphan.")
start.metadata.v <- text.v[1:start.v -1]
end.metadata.v <- text.v[(end.v+1):length(text.v)]
metadata.v <- c(start.metadata.v, end.metadata.v)
novel.lines.v <- text.v[start.v:end.v]
novel.v <- paste(novel.lines.v, collapse=" ")
novel.lower.v <- tolower(novel.v)
moby.words.l <- strsplit(novel.lower.v, "\\W")
moby.word.v <- unlist(moby.words.l)
not.blanks.v <- which(moby.word.v!="")
moby.word.v <- moby.word.v[not.blanks.v]
whale.hits.v <- length(moby.word.v[which(moby.word.v=="whale")])
total.words.v <- length(moby.word.v)
moby.freqs.t <- table(moby.word.v)
sorted.moby.freqs.t <- sort(moby.freqs.t , decreasing=T)
sorted.moby.rel.freqs.t <- 100*(sorted.moby.freqs.t/sum(sorted.moby.freqs.t))
plot(sorted.moby.rel.freqs.t[1:10], type="b", xlab="Top Ten Words", ylab="Percentage of Full Text", xaxt="n")
most.freq.words.v <- c("to", "the", "of", "and", "her", "i", "in", "a", "was", "it", "his", "that")
47 changes: 47 additions & 0 deletions Guemmer_Christoph/18_10/MelvilleAustenCombined.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
text.v <- scan("R/TextAnalysisWithR/data/plainText/austen.txt", what="character", sep="\n")
start.v <- which(text.v=="CHAPTER 1")
end.v <- which(text.v=="THE END")
start.meta.v <- text.v[1:start.v -1]
end.meta.v <- text.v[(end.v+1) :length(text.v)]
metadata.v <- c(start.meta.v, end.meta.v)
novel.lines.v <- text.v[start.v:end.v]
novel.v <- paste(novel.lines.v, collapse=" ")
novel.lower.v <- tolower(novel.v)
austen.words.l <- strsplit(novel.lower.v, "\\W")
austen.word.v <- unlist(austen.words.l)
not.blanks.v <- austen.word.v[which(austen.word.v!="")]
austen.freqs.t <- table(not.blanks.v)
sorted.austen.freqs.t <- sort(austen.freqs.t, decreasing=TRUE)
most.freq.v <- sorted.austen.freqs.t[1:10]
plot(most.freq.v, xlab="Words", ylab="Total Frequency in the Book")
sorted.austen.rel.freqs.t <- 100*(sorted.austen.freqs.t/sum(sorted.austen.freqs.t))
rel.most.freq.v <- sorted.austen.rel.freqs.t[1:10]
plot(rel.most.freq.v, type="b", xlab="Top Ten Words", ylab="Percentage of Full Text", xaxt ="n")
axis(1,1:10, labels=names(sorted.austen.rel.freqs.t [1:10]))
most.freq.words.v <- c("to", "the", "of", "and", "her", "i", "in", "a", "was", "it", "his", "that")
text.v <- scan("R/TextAnalysisWithR/data/plainText/melville.txt", what="character", sep="\n")
start.v <- which(text.v == "CHAPTER 1. Loomings.")
end.v <- which(text.v == "orphan.")
start.metadata.v <- text.v[1:start.v -1]
end.metadata.v <- text.v[(end.v+1):length(text.v)]
metadata.v <- c(start.metadata.v, end.metadata.v)
novel.lines.v <- text.v[start.v:end.v]
novel.v <- paste(novel.lines.v, collapse=" ")
novel.lower.v <- tolower(novel.v)
moby.words.l <- strsplit(novel.lower.v, "\\W")
moby.word.v <- unlist(moby.words.l)
not.blanks.v <- which(moby.word.v!="")
moby.word.v <- moby.word.v[not.blanks.v]
whale.hits.v <- length(moby.word.v[which(moby.word.v=="whale")])
total.words.v <- length(moby.word.v)
moby.freqs.t <- table(moby.word.v)
sorted.moby.freqs.t <- sort(moby.freqs.t , decreasing=T)
sorted.moby.rel.freqs.t <- 100*(sorted.moby.freqs.t/sum(sorted.moby.freqs.t))
plot(sorted.moby.rel.freqs.t[1:10], type="b", xlab="Top Ten Words", ylab="Percentage of Full Text", xaxt="n")
most.freq.words.v <- c("to", "the", "of", "and", "her", "i", "in", "a", "was", "it", "his", "that")
unique(sorted.austen.freqs.t[most.freq.words.v])
unique(sorted.moby.freqs.t[most.freq.words.v])
austen.top.ten.v <- c("to", "the", "of", "and", "her", "a", "i", "in", "was", "it")
moby.top.ten.v <- c("the", "of", "and", "a", "to", "in", "that", "it", "his", "i")
same.v <- austen.top.ten[which(austen.top.ten%in%moby.top.ten)]
same.v
Binary file not shown.
Binary file not shown.