我將如何嘗試爲以下函數編寫摘要方法,使用它來查找文本塊中的單詞總數和文本中使用的最頻繁的單詞?函數的摘要方法
編輯 - 換句話說,我想返回以下函數的摘要對象並將其格式化爲摘要。
findwords = function(tf) {
txt = unlist(strsplit(tf,' '))
wl = list()
for(i in 1:length(txt)) {
wrd = txt[i]
wl[[wrd]] = c(wl[[wrd]],i)
}
return(wl)
}
我已經試過
summary.findwords = function(obj) {
txt = unlist(strsplit(obj,' '))
cat(「the total number of words\n」)
print(length(txt))
cat(「the frequency of words\n」)
print(rev(sort(table(txt))))
}
你的意思是你想返回一個'summary'對象和格式化它像一個總結的隨機樣本? – 2014-11-03 17:08:22
是的。我很抱歉的混淆。這個問題我很不清楚。我找不到很多解釋它的信息。但是,是的,這是我想嘗試做 – ronan10 2014-11-03 17:11:48