[英]R Error in if-nest and/or for-loop? Unexpected '}' in "}"
I'm trying to work with a table called 'data' in R .我正在尝试使用R中名为 'data' 的表。
My code is roughly like this:我的代码大致是这样的:
for (i in nrow(data):1) {
data$meanApproval[i] = mean(data[max(1,i-11):i,5])
if(data$Poll = data[duplicated(data$Poll),]) {
data = data[!duplicated(data$Poll),]
}
}
It throws the error as in the title:它抛出了标题中的错误:
"Unexpected '}' in "}""
“在“}”中出现意外的“}”
The syntax before I added this code gave no complaint, so I'm sure it's the section I've posted.添加此代码之前的语法没有任何抱怨,所以我确定这是我发布的部分。
I know this may be considered a duplicate question, but I've studied all the other answers, and none of them help me with this issue.我知道这可能被认为是一个重复的问题,但我已经研究了所有其他答案,但没有一个能帮助我解决这个问题。 I can't find any missing bracket matches, and none of these are the result of a unicode misread.
我找不到任何丢失的括号匹配,而且这些都不是 unicode 误读的结果。
Any help would be greatly appreciated.任何帮助将不胜感激。
The error message was misleading from the actual error in the code.错误消息与代码中的实际错误具有误导性。
if(data$Poll = data[duplicated(data$Poll),]) {
...
}
should have read ==
for the if
check应该阅读
==
以进行if
检查
if(data$Poll == data[duplicated(data$Poll),]) {
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.