我试图在r中编写一个代码,通过导出和分析推文进行情绪分析,以下代码应该清理推文调用情绪包进行评分并返回结果,此代码已被引用在许多科技博客中,代码如下:
score.sentiment = function(sentences , pos.words, neg.words , progress='none')
{
require(plyr)
require(stringr)
scores = laply(sentences,function(sentence,pos.words,neg.words)
{
sentence =gsub('[[:punct:]]','',sentence)
sentence =gsub('[[:cntrl]]','',sentence)
sentence =gsub('\\d+','',sentence)
sentence=tolower(sentence)
word.list=str_split(sentence,'\\s+')
words=unlist(word.list)
pos.matches=match(words,pos.words)
neg.matches=match(words,neg.words)
score=sum(pos.matches)-sum(neg.matches)
return(score)
},pos.words,neg.words,.progress=.progress)
scores.df=data.frame(scores=scores,text=sentences)
return(scores.df)
}
但是我继续收到以下错误:
score.sentiment出错(Datasetgaza $ text,pos.words,neg.words,.progress =" text"): 未使用的参数(.progress =" text")
通过的论点是: gaza.scores = score.sentiment(Datasetgaza $文本,pos.words,neg.words,.progress ='文本&#39)
非常感谢任何有关代码的帮助
答案 0 :(得分:0)
你错过了一个'。'在进步面前。 确定这会有所帮助。
score.sentiment = function(sentences , pos.words, neg.words , .progress='none')
{
require(plyr)
require(stringr)
scores = laply(sentences,function(sentence,pos.words,neg.words)
{
sentence =gsub('[[:punct:]]','',sentence)
sentence =gsub('[[:cntrl]]','',sentence)
sentence =gsub('\\d+','',sentence)
sentence=tolower(sentence)
word.list=str_split(sentence,'\\s+')
words=unlist(word.list)
pos.matches=match(words,pos.words)
neg.matches=match(words,neg.words)
score=sum(pos.matches)-sum(neg.matches)
return(score)
},pos.words,neg.words,.progress=.progress)
scores.df=data.frame(scores=scores,text=sentences)
return(scores.df)
}