How do I add a prefix to several variable names using dplyr?

后端 未结 5 1717
花落未央
花落未央 2020-12-10 03:06

I\'m trying to add a common prefix to each of the variable names in a data.frame. For example, using the mtcars data, I could add the prefix \"cars.\" using th

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-10 03:37

    For future readers, dplyr now can do this with the select_if, select_at, and select_all functions:

    dplyr::select_all(mtcars, .funs = funs(paste0("cars.", .)))
    

提交回复
热议问题