Hello I want to apply dplyr arrange function on a column within a for loop, but for some reason it does not work. Here is a minimal example:
for (j in colnames(df1)[3:ncol(df1)]){
# create datframe for each column
t <- select(df1, all_of(j))
t %>% arrange(j)
var_list[[j]] <- t
for (i in var_list[[j]]$Timestep )
### arrange each timestep df by each colun once
scenario[[i+1]] <- var_list[[j]][min:max,]
# subset data to the scenarios of interest
}
I guess the Problem is that j delivers a character string "variable", but dplyr arrange requires it without "". I have tried as.name(), paste() and eval parse functions but neither of them worked. Any ideas? Thank you!