顺序重命名具有特异名称的100多个列 [英] Sequentially Rename 100+ Columns Having Idiosyncratic Names

查看:66
本文介绍了顺序重命名具有特异名称的100多个列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Google表单调查中导入了一个很大的数据框,其中的列名非常长(基本上,列名本身就是调查问题).

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

目标:用序列名称(例如Q1,Q2等)替换这些特殊的长列名称.

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

推荐答案

使用colnames函数:

Use the colnames function:

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

这篇关于顺序重命名具有特异名称的100多个列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆