【发布时间】:2018-05-14 14:13:56
【问题描述】:
我想知道为什么在运行以下 R 函数时,我收到以下警告:
Warning message:
In if (is.na(labels)) axTicks(2) else labels :
the condition has length > 1 and only the first element will be used
由于除了此警告消息外一切正常,我想知道如何消除此警告消息?
bb <- function(labels = NA){
plot(1, yaxt = "n")
lab <- if(is.na(labels)) axTicks(2) else labels ## Why this gives a warning message?
axis(2, at = axTicks(2), labels = lab)
}
# Example of use:
bb(labels = paste0("Hi ", 1:5))
【问题讨论】:
-
is.na(labels)将返回一个由 TRUE/FALSE 值组成的 vector,在if语句中只计算第一个值。您是否尝试替换labels中的任何 NA 值? -
@jdobres,没错!
标签: r function if-statement plot