How to order column names of r dataframe with respect to other dataframe column order -


this question has answer here:

i have r dataframe column orders follows

      name,id,class,division 

i have dataframe same columns but,with different order.

     id,class,division,name 

i want above dataframe column orders same of first one. how can achieve in r?

we can order second dataframe columns using column names of first (assuming both of them have same column names)

df2[names(df1)] 

if data.table, use setcolorder

library(data.table) setcolorder(df2, names(df1)) 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -