如果有错误的状态我从未见过 [英] if statemtent with error I never seen
本文介绍了如果有错误的状态我从未见过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不明白这个错误:
Warning message:
In if ((t$carried2 == t$Dead5) & (t$carried2 == t$Dead6)) { :
the condition has length > 1 and only the first element will be used
我的代码:
if ((t$carried2 == t$Dead5) & (t$carried2 == t$Dead6)) {(t$Dead5 = 0) & (t$Dead6 = 0)}
这可能很糟糕,但我是新手。无论如何,我想说是否(这个和那个发生){那么这个和那个
This is probably crappy, but I am new. Anyways, I want to say if (this and that happen) {then this and that = 0
推荐答案
这个怎么样:
indices <- (t$carried2 == t$Dead5) & (t$carried2 == t$Dead6)
t$Dead5[indices] <- 0
t$Dead6[indices] <- 0
设置 t $ Dead5
和 t $的值Dead6
为零,在那些条件为 TRUE
的行中。
This sets the the values of t$Dead5
and t$Dead6
to zero, in those rows where the condition is TRUE
.
你说在您的评论中,您要清理数据框。以下是删除 indices
TRUE
的行的方法。使用指数
,如上所述:
You say in your comment that you want to clean up the data frame. Here is how you remove the rows for which indices
is TRUE
. With indices
as above:
t <- t[!indices,]
这篇关于如果有错误的状态我从未见过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文