We wish to obtain a set of columns of a data frame, that contains some or all columns, sorted in a given order.
This section is organized as follows:
We wish to change the locations of the columns of a data frame by spelling out their names in the desired order.
df_2 = df %>%
select(col_3, col_1, col_4, col_2)
Here is how this works:
select()
. See Basic Selecting.select()
will be dropped. See Relative Relocating for how to relocate certain columns relative to the rest.We wish to change the locations of the columns of a data frame by spelling out their numerical positions (in the original data frame) in the desired order.
df_2 = df %>%
select(3, 1, 4, 2)
Here is how this works:
select()
.