1

I am working on some country specific information and right now, my data looks like this:

score country      code  prev.score
  1    Brazil      BRA      5
  2    Singapore   SIN      3
  3    France      FRA      4

How do I convert the country to be the focal point of the data, Ideally to look like this:

          Score Code  prev.score
Brazil     1    Bra    5
Singapore  2    SIN    3
France     3    FRA    4

Thank you.

  • `df %>% select(country, everything())` if you want to keep the column name. `df %>% column_to_rownames(country)` otherwise. – Roman Dec 05 '21 at 05:56

1 Answers1

0

You can use tibble::column_to_rownames.

library(tibble)

tibble::column_to_rownames(df, "country")

Output

          score code prev.score
Brazil        1  BRA          5
Singapore     2  SIN          3
France        3  FRA          4

Data

df <-
  structure(
    list(
      score = c(1, 2, 3),
      country = c("Brazil", "Singapore",
                  "France"),
      code = c("BRA", "SIN", "FRA"),
      prev.score = c(5, 3,
                     4)
    ),
    class = "data.frame",
    row.names = c(NA,-3L)
  )
AndrewGB
  • 16,126
  • 5
  • 18
  • 49