我的數據框:在數據幀減去兩列,如果滿足條件
Dead4 Dead5
0 0
0 0
0 0
1 2
0 0
0 0
1 2
0 0
1 0
0 1
1 1
5 10
我希望我的代碼,說隨時Dead5比Dead4更大同一行中減去兩個值,並將該值在Dead5
indices<- (t$Dead5 > t$Dead4)
t$Dead6[indices]<- (t$Dead6) - (t$Dead5)
Warning message:
In t$Dead6[indices] <- (t$Dead6) - (t$Dead5) :
number of items to replace is not a multiple of replacement length
有些人可以解釋我做錯了什麼,並幫我寫幾行代碼,這將做到這一點?
感謝您的解釋。這現在很有意義。 – Chad