I have two lists of dataframes, artrk_dist and comprk_dist. I am inner joining the corresponding datasets in the two lists using dplyr. I need to refer to the column names inside the join call using the index of the column rather than the column name itself. I tried using colnames(dataset)[index], but this doesn't work. I have this:
 allrk_dist<- inner_join(artrk_dist[[1]],comprk_dist[[1]], 
                                 by=c(colnames(artrk_dist[[1]])[1]= 
                                        colnames(comprk_dist[[1]])[1],
                                      colnames(artrk_dist[[1]])[2]= 
                                        colnames(comprk_dist[[1]])[2]))
    
    
BUt this gives an error:
Error: unexpected '=' in:
" allrk_dist[[1]]<- inner_join(artrk_dist[[1]],comprk_dist[[1]], 
                                 by=c(colnames(artrk_dist[[1]])[1]="
>                                         colnames(comprk_dist[[1]])[1],
Error: unexpected ',' in "                                        colnames(comprk_dist[[1]])[1],"
>                                       colnames(artrk_dist[[1]])[2]= 
+                                         colnames(comprk_dist[[1]])[2]))
Error: unexpected ')' in:
"                                      colnames(artrk_dist[[1]])[2]= 
                                        colnames(comprk_dist[[1]])[2])"
> 
Here is an example of what I'm doing which gives an error as above:
data1<- data.frame(a1=1:5,b1=6:10)
 data2<- data.frame(a2=2:6,b2=5:9)
 data_list<-list(data1,data2)
 y<- inner_join(data_list[[1]],data_list[[2]],by=colnames(data_list[[1]])[1]
                = colnames(data_list[[2]])[1])
I need to refer to the column names using an index and I am stuck there.
 
    