Change column names in dataframe based on matching to another dataframe by dplyr
We could use match
names(df)[-1] <- as.character(df2$Tumor_name[match(names(df)[-1], df2$Sample_name)])
df
# Gene_Symbol Tumor56 Tumor17 Tumor99 Tumor2 Tumor34 Tumor84 Tumor51
#1 Gene1 85657.98 10423.41 18778.68 23919.53 NA NA NA
#2 Gene2 54417.79 41660.73 43655.80 47829.02 46677.20 68596.23 80506.15
#3 Gene3 110949.33 40094.55 NA NA 63389.45 56802.61 48722.99
#4 Gene4 53197.45 49519.78 57447.09 51478.58 48722.15 44712.64 38629.01
#5 Gene5 87156.80 129387.11 113266.15 116275.34 NA NA NA
#6 Gene6 NA NA 44810.26 43110.95 77135.52 47744.18 37885.00
#7 Gene7 23880.28 23903.26 26316.65 25417.46 40265.69 33689.63 36638.02