2016-07-21 38 views
-2

是否有一種方法可以使用R來查找文本文件的平均句子長度?還是有比使用R更好的方法?只是爲了給出一些背景,我是一個非常新的編程和這個論壇。要求人們共享代碼是否合適?如果沒有,任何人都可以指向幫助頁面/教程?將R用於文本文件的平均句子長度

+2

歡迎來到SO。請閱讀[如何在R中提供最小重現性示例](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610)。然後相應地編輯並改進它。一個好的帖子通常會提供最少的輸入數據,期望的輸出和一些代碼嘗試 - 全部複製 - 粘貼 - 運行。 – lukeA

回答

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 

還有許多其他的方式來實現你想要什麼,我猜。

相關問題