Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
446 views
Welcome To Ask or Share your Answers For Others

1 Answer

Use the colnames function:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...