![](/img/trans.png)
[英]How to add a new column based on multiple conditions of the other columns in r
[英]How to add new column based on other columns
我的數據在兩個向量中包含0
和1
值:
bad = c(1,0,0,1,0,1,1)
good = c(1,0,0,0,1,0,0)
我想根據這兩列創建新列。 如果bad
和good
等於0
(或1
),則新列中的觀察值必須為0
(或1
),或者如果bad
為1
good
為0
,則新列中的新觀察值應為1
,反之亦然。
可能是您要求使用其中一個邏輯運算符。
或者
as.integer(bad | good)
和
as.integer(bad & good)
有關更多信息,請參閱https://stat.ethz.ch/R-manual/R-devel/library/base/html/Logic.html 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.