R dplyr: Non-Standard Evaluation difficulty. Would like to use dynamic variable names in filter and mutate

后端 未结 2 1150
隐瞒了意图╮
隐瞒了意图╮ 2021-01-14 03:31

I have created a reproducible example to illustrate the problem I am having with non-standard evaluation in R (dplyr). I would like to use dynamic variable names in the scen

2条回答
  •  生来不讨喜
    2021-01-14 04:11

    Here is one option with parse_expr from rlang

    library(rlang)
    library(dplyr)
    patientData %>%
            filter(!! parse_expr(paste(firstDateName, ">", secondDateName)))
    #   patientID    birth_d    treat_d    death_d
    #1         5 2017-01-01 2011-12-27 2012-12-26
    #2         7 2011-06-25 2012-06-24 2001-01-01
    #3        12 2018-05-05 2013-09-17 2014-09-17
    

提交回复
热议问题