Test for NA and select values based on result

后端 未结 1 2011
耶瑟儿~
耶瑟儿~ 2020-12-15 17:16

My question is rather simple. What I want is if A[i]!=NA, then C[i]=A[i], if A[i]=NA, then C[i]=B[i], however, I always g

相关标签:
1条回答
  • 2020-12-15 17:44

    use is.na :

    DF <- within(DF,
       C <- ifelse(!is.na(A),A,B)
    )
    

    with DF being your dataframe.

    0 讨论(0)
提交回复
热议问题