I wish to order a data frame based on different columns, one at a turn. I have a character vector with the relevant column names on which the order should be based:
parameter <- c("market_value_LOCAL", "ep", "book_price", "sales_price", "dividend_yield",
"beta", "TOTAL_RATING_SCORE", "ENVIRONMENT", "SOCIAL", "GOVERNANCE")
I wish to loop over the names in parameter and dynamically select the column to be used to order my data:
Q1_R1000_parameter <- Q1_R1000[order(Q1_R1000$parameter[X]), ]
where X is 1:10 (because I have 10 items in parameter).
To make my example reproducible, consider the data set mtcars and some variable names stored in a character vector cols. When I try to select a variable from mtcars using a dynamic subset of cols, in a similar way as above (Q1_R1000$parameter[X]), the column is not selected:
cols <- c("cyl", "am")