我将如何尝试为以下函数编写摘要方法,使用它来查找文本块中的单词总数和文本中使用的最频繁的单词?函数的摘要方法
编辑 - 换句话说,我想返回以下函数的摘要对象并将其格式化为摘要。
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