0

I have a dataframe in R like the following, I want to move the columns. For example, bring the third column to the first column and vice versa. Can you please help me with that? For example I want to build new df with columns " datathonpresevative, datathoncountry, datathoncoordinates, and so on".

I know maybe this question seems dumb, but I am new to R. enter image description here

  • Hi Mostafa Alaverdi, you are in fact looking for "How does one reorder columns in a data frame?", see this above SO question for answers and [how-to-make-a-great-r-reproducible-example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) to improve your reproducible examples. – cbo Sep 01 '22 at 07:23

1 Answers1

0
library(tidyverse)

# Move the third column to first 
df %>%  
  relocate(3)

# Subset columns
df %>%  
  select(datathonpresevative, datathoncountry, datathoncoordinates)
Chamkrai
  • 5,912
  • 1
  • 4
  • 14