Sequentially Rename 100+ Columns Having Idiosyncratic Names

我怕爱的太早我们不能终老 提交于 2019-12-09 03:56:02

问题


I have a large data frame imported from a Google Forms survey with very long column names (basically, the column names are the survey questions themselves).

So, my imported data frame is like this:

      d<-
  data.frame(LongnameLongnameLongnameLongname=1:3,AnotherOneAnotherOneAnotherone=4:6, Etc_Etc_Etc_Etc_Etc=3:5)
      d

GOAL: To replace these long, idiosyncratic column names with a sequential name, such as Q1, Q2, etc.


回答1:


Use the colnames function:

colnames(d) <- paste0("Q",1:ncol(d))


来源:https://stackoverflow.com/questions/41510225/sequentially-rename-100-columns-having-idiosyncratic-names

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!