Append suffix to colnames

Anna Gorald picture Anna Gorald · Feb 29, 2016 · Viewed 19.4k times · Source

I have multiple columns of different names in a data frame. For all of them i would like to add a common suffix

tot_proc

So, for example

DF
a   b   c

->

DF
a_tot_proc   b _tot_proc   c_tot_proc

I was able only to figure out how to add a prefix for column names:

colnames(DF) <- paste("tot_proc", colnames(DF), sep = "_")

but not suffix.Could you please help me. Thank you!

Answer

jmaval picture jmaval · Dec 19, 2017

You could just switch the order around.

colnames(DF) <- paste(colnames(DF), "tot_proc", sep = "_")