How to include NA in ifelse?

前端 未结 5 649
走了就别回头了
走了就别回头了 2020-12-15 03:05

I am trying to create a column ID based on logical statements for values of other columns. For example, in the following dataframe

test <- st         


        
5条回答
  •  轮回少年
    2020-12-15 03:54

    So, I hear this works:

    Data$X1<-as.character(Data$X1)
    Data$GEOID<-as.character(Data$BLKIDFP00)
    Data<-within(Data,X1<-ifelse(is.na(Data$X1),GEOID,Data$X2)) 
    

    But I admit I have only intermittent luck with it.

提交回复
热议问题