Moving from deprecated summarize_ to new summarize in dplyr

后端 未结 2 1842
挽巷
挽巷 2021-01-23 23:29

I have a function that calculates the means of a grouped database for a column which is chosen based on the content of a variable VarName. The current function uses

2条回答
  •  无人共我
    2021-01-24 00:33

    Use !! with as.name or as.symbol:

    dat %>% 
        group_by(Grade) %>% 
        summarize(means = mean(!!as.name(VarName), na.rm=T))
        # or summarize(means = mean(!!as.symbol(VarName), na.rm=T))
    
    # A tibble: 2 x 2
    #  Grade means
    #   
    #1  2.00  90.0
    #2  3.00  77.5
    

提交回复
热议问题