我想在调查数据中找到一个孩子的兄弟姐妹,检查是否有年龄为<= 1岁的兄弟姐妹,并存储结果(1,0)。
这是我的数据:
<表类>
集群
house_number
年龄
tbody><<tr>1 5 0 15 1 18 4 121 4 121 1 222 0 236 0 25 0 25 2 25 3 表类>
你的意思是:
# let's call your dataframe : data
# we create a new column called sibling_age on the condition of the age column
# and we use the ifelse function
# the first value represents the if argument
# the second value represents the else argument
data$sibling_age = ifelse(data$age>1,1,0)
# I hope that this is what you were looking for.