所以我的任务基本上是得到下面的图表。数据来自数据帧,其中某些值已标记为NA。因此,我的代码如下:
> plot(temp,ozone,
+ xlab = "temperature",
+ ylab = "ozone",
+ col = ifelse(which(ozone>100), "red", "orange",),
+ pch = 17)然而,我现在收到一个错误:
"Error in ifelse(which(ozone > 100), "red", "orange", ) :
unused argument (alist())如果有任何关于哪里出了问题的反馈/建议,我将不胜感激。我之前也尝试过这样的东西:
highlevels <- which(ozone>100)
lowlevels <- which(ozone<100)
col = c("red","orange")[highlevels,lowlevels]然而,很明显,这并不是很有效。

发布于 2020-05-02 01:30:51
去掉which并将其包装在另一个ifelse中是一种选择:
plot(temp, ozone,
xlab = "temperature",
ylab = "ozone",
col = ifelse(ifelse(!is.na(ozone), ozone, 0) > 100, "red", "orange"),
pch = 17)另外,如果您正在使用这些库,像tidyr::replace_na或dplyr::coalesce这样的函数可以为您提供帮助。
另一种选择是将所有变量子集为非缺失变量。
还有一个是设置
col = c("red", "orange")[(ozone > 100) + 1]但这有点棘手。
https://stackoverflow.com/questions/61547386
复制相似问题