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??
Asked
Active
Viewed 2,635 times
2
-
Can you send you dataframe by using 'dput' – Simon Besnard Nov 07 '14 at 18:14
-
How can I do that? I guess I need help with this also..sorry! – jonas Nov 07 '14 at 18:23
1 Answers
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