programmatically rename columns in dplyr

前端 未结 2 1267
青春惊慌失措
青春惊慌失措 2021-01-01 01:10

I can rename column in dplyr like this:

mtcars %>% dplyr::rename(\'cylinder\'=cyl)

However, if I would like to change column names progr

2条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 01:44

    The simplest solution currently to programmatically rename in dplyr is to use the tripple bang (!!!)

    library(dplyr)
    cnames = c('cylinder' = 'cyl', 'mile_per_gallon' = 'mpg')
    mtcars %>% rename(!!!cnames)
    

提交回复
热议问题