I have two dataframes with the same number of columns. I’m writing a function that takes the two dataframes and an integer n as arguments and needs to sort each dataset by its respective nth column. Essentially, how can I sort a dataframe by it’s nth column without having to know the label of that column?
Share
A slight modification to an answer here:
How to sort a dataframe by column(s)?
Alternatively, you could just look up the label with
colnames(dd)[n]and use that with any of the methods in the above link.