Change order of column in data frame

Hello,
I need to change the order of a certain data frame.
The difficulty is how to move one column after another.
I mean, move the column "dfg" before "kol".
I have no idea how to perform this simple task.
Can you help me?
Thanks for your time and interest

Hi, one way to do is, is to use the select() function from the dplyr package, one of the core packages from tidyverse. select() is a function to select variables from a data frame, but can be used to change the order of columns in a data frame as well.

See the examples in the reference of the select() function: https://dplyr.tidyverse.org/reference/select.html or the chapter on in the excellent introduction R for Data Science https://r4ds.had.co.nz/transform.html#select

In the soon to be released version 1.0.0 of dplyra new function relocate() will make this even more comfortable (see https://www.tidyverse.org/blog/2020/03/dplyr-1-0-0-select-rename-relocate/).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.