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

'hasOwnProperty' in javascript -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

android - Unable to generate FCM token from dynamically instantiated Firebase -