How to order column names of r dataframe with respect to other dataframe column order -
this question has answer here:
- order column names [closed] 2 answers
- ordering columns of data frame 2 answers
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
Post a Comment