mean word length

# july 31, 2013
# v3: updated on Aug 2 2013. added calculations of sample mean & sample SD
# Goal: to make histograms of all novels from all decades

# source the script that contains my functions
source("countWordLengths_v1.R")
files <- dir("texts/", pattern = ".txt", recursive = TRUE)
sd.out<- vector(length = length(files))
mean.out<- vector(length = length(files))
for (i in 1:length(files))
{
fn <- files[i]
aa <- wordLength(getNovelWords(paste0("texts/",fn)))
#png(paste0("texts/", fn, ".png"))
#hist(wordLength(getNovelWords(paste0("texts/",fn))), main= fn, freq=FALSE)
# use freq = FALSE above to have same scale for all
#dev.off()
mean.out[i]<- mean(aa)
sd.out[i]<- sd(aa)
names(sd.out)[i]<- fn
names(mean.out)[i]<- fn
}

write.csv(cbind(mean.out, sd.out), "meanWordLengthByText.csv")