I would like to order the columns of the data frame according to the text variables given in the column of another data frame (using srtcolorder
from the data.table
). Let's say, that i have first data frame (df1)
with columns named and ordered as "five", "two" "three", "one", "four", and have another data frame with the column (df2$names
), containing the string variables ordered as "one", "two", "three", "four", "five". How can I order the columns of the df1, according to the variables in df2$names
?
I have tried to use setcolorder
as follows:
gf3<-setcolorder(df1, key=df2$names)
And get an error message
Error in setcolorder(df1, key = df2$names) : unused argument (key = df2$names)