r - 由于意外的“}”而出错 - R 中的问题。如何解决?
问题描述
for (i in 1:214)
{
temp1 <- subset(perm2, perm2$isin == list[1+i])
temp2 <- subset(temp1, temp1$Price != "NA")
tempstart <- min(temp2$Time)
if (is.na(tempstart))
{
tempstart = "01/01/2020" else tempstart = tempstart
}
temp3 <- perm2[perm2$isin == list[1=i] & perm2$Time >= tempstart]
perm3 <- rbind(perm3,temp3)
}
我正在编写一个将一堆数据绑定在一起的函数。不幸的是,我的一些数据不起作用,我需要指定一个日期来观察日期。
但后来我得到了意想不到的}问题>>“错误:“}”中的意外'}'”
谁能解释一下?
谢谢你。
解决方案
The if
condition loop also wraps the else
inside, instead it should end followed by else
tempstart = "01/01/2020" else tempstart = tempstart
would be
tempstart = "01/01/2020"
} else {tempstart <- tempstart}
Without a small reproducible example, it is not clear about the structure of the objects. Considering the "list" as list
and NA
as real NA,
for(i in 1:214){
temp1 <- subset(perm2, isin == list[[1+i]] & !is.na(Price))
tempstart <- min(temp1$Time)
if(is.na(tempstart)) {
tempstart <- "01/01/2020"
}
temp3 <- perm2[perm2$isin == list[[i-i]] & perm2$Time >= tempstart,]
perm3 <- rbind(perm3,temp3)
}
Also, the i + 1
, assumes that the list
have length of 215 or else when i is 214, there won't be corresponding element for list
推荐阅读
- computer-vision - 人脸识别:种族属性
- python - 如何定位缩略图 discord.py?
- java - 如何从 ArrayList 中获取具有相同对象属性的对象列表
- postgresql - 为什么我做 LEFT JOIN 时没有应用优化?
- javascript - JS解释器如何工作?
- python - 将csv转换为数据框
- algorithm - 如何证明归并排序和插入排序的时间复杂度?
- docker - Has anyone modified the port number of orderer.example.com in the docker-compose-base.yaml file in fabric1.4 and then started the network?
- bitmap - 如何在 ESP32-CAM 上裁剪位图图像?
- javascript - How do I implement filter in React with redux and reset data without making fresh API call?