Warning message: the condition has length > 1 and only the first element will be used
Posted Data+Science+Insight
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Warning message: the condition has length > 1 and only the first element will be used相关的知识,希望对你有一定的参考价值。
Warning message:In if (x > 1) :the condition has length > 1 and only the first element will be used
目录
Warning message:In if (x > 1) :the condition has length > 1 and only the first element will be used
问题:
#想把向量中元素大于1的乘以2;
#如下方法把所有的元素都乘以了2
#define data
x <- c(2, 3, 1, 1, 5, 7)
#if value in vector x is greater than 1, multiply it by 2
if (x>1)
x*2
[1] 4 6 2 2 10 14
解决:
#使用ifelse语法
#if value in vector x is greater than 1, multiply it by 2
ifelse(x>1, x*2, x)
[1] 4 6 1 1 10 14
完整问题:
> #define data
> x <- c(2, 3, 1, 1, 5, 7)
>
> #if value in vector x is greater than 1, multiply it by 2
> if (x>1)
+ x*2
+
[1] 4 6 2 2 10 14
Warning message:
In if (x > 1) :
the condition has length > 1 and only the first element will be used
参考:R
参考:How to Fix in R: the condition has length > 1 and only the first element will be used
以上是关于Warning message: the condition has length > 1 and only the first element will be used的主要内容,如果未能解决你的问题,请参考以下文章
Error in file(file, “rt“) : cannot open the connection In addition: Warning message:In file(file, “
R语言message函数warning()函数和stop()函数输出程序运行健康状态信息实战
unused function warning message
Which Clang Warning Is Generating This Message?
warning C4819 解决方案 warning C4819: The file contains a character that cannot be represented in the cu