You can reorder multiple data columns in R so that the oldest is on the left and the newest is on the right using the select
function along with the everything()
function from the dplyr
package.
Here is an example code snippet showing how to reorder the columns:
287 chars11 lines
In the example above, columns are reordered so that the first column remains the same (ID), the newest column "Age" is on the right, and the intermediate columns are shifted according to the new order.
This will result in the columns being reordered with the oldest on the left and the newest on the right in the dataframe.
gistlibby LogSnag