Hello i am new to R programming and i am stuck with one problem. I would like to combine 2 dataframe into a new one in this way. First column of first dataframe, first column of second dataframe and then the third column of the new dataframe should be the difference between the 2 columns before, and iterate the process for all the columns of the dataframe ( they have same size of course). The crucial point is that the new columns should have their name unchanged.... this is where i get stuck. Please help meeee
i tried to iterate a for loop and combine through cbind but then i don't know how to leave the column names unchanged
If you cbind the data.frames you will get the original column names which I think was your goal. You can then rearrange the columns with a trick that depends on how R matrices behave when "unfolded" with the
c()
function:So make such a matrix that depends on twice the length of the dataframes and then use it to reorder the result of cbind()-ing: