0

I want to transform a csv or excel table (with rows in one order and eg 20 columns with head) into another table with same rows in other pre-established order.

Thank you very much

  • Welcome to stack overflow. It's easier to help you if you make your question reproducible by including data to enable testing and verification of possible solutions. [Link for guidance on asking questions](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Peter Mar 14 '22 at 13:39

1 Answers1

0

suppose your table looks a bit like this, once you've loaded it into r:

# Packages
library(tidyverse)

# Sample Table
df <- tibble(names = c("Jane","Boris","Michael","Tina"),
       height = c(167,175,182,171),
       age = c(26,45,32,51),
       occupation = c("Teacher","Construction Worker","Salesman","Banker"))

If all you want to do is reorder the columns, you can do the following:

df <- df %>%
  select(occupation,height,age,names)

There are other ways to do this, especially if you only want to move one or two columns out of your 20. But suppose you want to rearrange all of them, this will do it.

James
  • 463
  • 4
  • 13