Entering edit mode
19 months ago
Bio
•
0
Hi, I would like to change dataframe column names based on info id matching and select names from name column.
I tried to do it separately and it works. Here is the code.
colnames(df1) = sapply(colnames(df1), function(x) {
info$name[which(info$id == x)]
})
But when I am trying to do the same thing using for loop to do the same for two data frames,it does nothing.
for(df in c(colnames(df1), colnames(df2)){
df = sapply(df, function(x) {
info$name[which(info$id == x)]
})
}
Can someone help me to understand what I am doing wrong. Any help much appreciated!
Untested since no example data was provided.