Rename columns of a data frame by searching column name

后端 未结 4 1867
南旧
南旧 2021-02-06 14:44

I am writing a wrapper to ggplot to produce multiple graphs based on various datasets. As I am passing the column names to the function, I need to rename the column names so tha

4条回答
  •  一生所求
    2021-02-06 15:05

    require(plyr)
    df <- data.frame(col2=1:3,col1=3:5,col3=6:8)
    df <- rename(df, c("col1"="new_col1", "col2"="new_col2", "col3"="new_col3"))
    df
    

    And you can be creative in making that second argument to rename so that it is not so manual.

提交回复
热议问题