How to rename a column to a variable name “in a tidyverse way”

前端 未结 1 1565
广开言路
广开言路 2021-01-04 03:55

I\'ve created a simple data frame (dput below):

    date      ticker     value
------------------------------
  2016-06-30  A2M.ASX   0.0686
  2         


        
1条回答
  •  -上瘾入骨i
    2021-01-04 04:40

    With the newest dplyr (>0.7.0) you would use

    rename(df, !!metric:=value)
    

    The syntax is "new_name=old_name" and you need to use := with !! to put a variable on the left side of a parameter name.

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