Is there a way to use R to find the average sentence length of a text file? Or is there a better method than using R? Just to give some context, I'm an very new to programming and this forum. Is it appropriate to ask people to share code? If not, can anyone point me to a help page/tutorial?
Asked
Active
Viewed 793 times
-2
-
2Welcome to SO. Please read [how to provide minimal reproducible examples in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610). Then edit & improve it accordingly. A good post usually provides minimal input data, the desired output & some code tries - all copy-paste-run'able. – lukeA Jul 21 '16 at 19:18
1 Answers
0
Here's an example:
library(stringi)
txt <- paste(readLines(n=10), collapse=". ")
Do you remember the
21st night of September
Love was changing the minds of pretenders
While chasing the clouds away
Our hearts were ringing
In the key that our souls were singing
As we danced in the night
Remember how the stars stole the night away
Ba de ya - say do you remember
Ba de ya - dancing in September
summary(stri_length(stri_split_boundaries(txt, type = "sentence")[[1]]))
# Min. 1st Qu. Median Mean 3rd Qu. Max.
# 25.00 31.00 32.00 35.56 43.00 46.00
There are many other ways to achieve what you want, I guess.

lukeA
- 53,097
- 5
- 97
- 100