Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Append suffix to colnames

Tags:

r

suffix

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!

like image 613
Anna Gorald Avatar asked Feb 29 '16 11:02

Anna Gorald


1 Answers

You could just switch the order around.

colnames(DF) <- paste(colnames(DF), "tot_proc", sep = "_")
like image 115
jmaval Avatar answered Nov 15 '22 23:11

jmaval