Filling in a new column based on a condition in a data frame

前端 未结 2 459
天命终不由人
天命终不由人 2020-12-12 01:31

I want to add a new column in my data frame so that for each row if LOC == 1 then V is equal to the value given for V1; if LOC==

2条回答
  •  有刺的猬
    2020-12-12 02:26

    If LOC only contains 1 or 2 then this will work

     df$V <- ifelse(df$LOC == 1, df$V1, df$V2)
    

提交回复
热议问题