Rename multiple dataframe columns, referenced by current names

后端 未结 5 1925
-上瘾入骨i
-上瘾入骨i 2020-12-24 05:40

I want to rename some random columns of a large data frame and I want to use the current column names, not the indexes. Column indexes might change if I add

5条回答
  •  庸人自扰
    2020-12-24 06:09

    You can use the str_replace function of the stringr package:

    names(mydf) <- str_replace(names(mydf), "MyName.1", "MyNewName")
    

提交回复
热议问题