I wanted to append a suffix or prefix to certain column names of df1 based on the names in df2. my df1 looks like this,
AE02 AE03 AE04 AE05 AE06 AE07 AE08 AE09 AE10 AE11 AE12
11.9619362364 18.5701402709 42.2010838789 28.0025053738 19.5589170223 18.1459582989 16.5292369479 32.4885640738 34.0342144643 31.6971000153 44.932255488
2.9904840591 3.9793157723 0 0 1.7780833657 1.7281865047 13.7743641233 4.3318085432 0 17.067669239 0
0 0 0 0 2.6671250485 0 4.5914547078 0 0 0 2.1396312137
and df2 looks like,
V1
AE06
AE08
AE09
AE12
I could replace those column name with new name as follows,
colnames(df1)[which(colnames(df1) %in% df2$V1 )] <- "DMR"
But I am looking for a solution where I can append as prefix to the column name instead of replacing it, for instance, my column names should like this,
AE02 AE03 AE04 AE05 DMR_AE06 AE07 DMR_AE08 DMR_AE09 AE10 AE11 DMR_AE12
Any suggestions and help is well apreciated