How to compare two columns in R data frame and return 0 or 1 in the third column based on the comparison?

后端 未结 2 1039
梦谈多话
梦谈多话 2021-01-29 14:49

I have a dataframe with two columns(both are dates) and a million rows. I have to compare both the dates and return value in the third column. i.e if date in column A is greater

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-29 14:58

    In base:

    DF$C <- as.numeric(DF$A > DF$B)
    

    In dplyr:

    DF %>% 
      mutate(C = as.numeric(A > B))
    

提交回复
热议问题