有没有办法用R来查找文本文件的平均句子长度?还是有比使用R更好的方法?只是为了给出一些背景信息,我对编程和这个论坛非常陌生。要求人们分享代码是否合适?如果没有,是否有人可以指向我的帮助页面/教程?
答案 0 :(得分:0)
以下是一个例子:
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
我猜,还有很多其他方法可以达到你想要的效果。