admin管理员组文章数量:1599543
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
本文标签: Messagewarningconditionelementlength
版权声明:本文标题:Warning message: the condition has length > 1 and only the first element will be used 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dongtai/1728323591a1154147.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论