2

I have a large dataframe with long column names in it. I would like to shorten the columnnames by dropping characters before a colon sign (:), the sign is present in every column name in the dataframe columns. Looking for a way to perform this on a dataframe??

user16217248
  • 3,119
  • 19
  • 19
  • 37
jonas
  • 13,559
  • 22
  • 57
  • 75

1 Answers1

4

Perhaps (third try):

names(df) <- sub("^(.+[:])", "", names(df))

Read that regex as " starting at the beginning of the character string, consider all the characters up to and including the last instance of ":" as a character grouping and replace with a null-string. (It's the last ":" because regex matching is "greedy".)

IRTFM
  • 258,963
  • 21
  • 364
  • 487