reverse the order of a column of a tibble using tidyverese in r

To reverse the order of a column in a tibble using tidyverse in R, we can use the mutate() and select() functions from the dplyr package. Here's an example:

main.r
library(dplyr)

# create a sample tibble
my_tibble <- tibble(x = c(1, 4, 3), y = c("a", "b", "c"))

# reverse the order of column x
my_tibble_reversed <- my_tibble %>% 
  mutate(x = rev(x)) %>% 
  select(x, everything())

my_tibble_reversed
241 chars
12 lines

In the mutate() function, we use the rev() function to reverse the order of column x. In the select() function, we use everything() to keep all the remaining columns in the tibble.

The resulting tibble (my_tibble_reversed) will have the same columns as the original tibble (my_tibble), but with the values in column x reversed.

gistlibby LogSnag