How to sort this data ?

Hi , I have got two character columns and I want to sort it according to specific order:

data1 <- structure(list(Arthritis = c("No", "No", "Yes", "Yes"), Soccer_type = c(
  "Non_Elite", "Elite", "Non_Elite"
), N = c(61L, 206L, 10L, 9L)), class = c(
  "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -4L), groups = structure(list(
  Arthritis = c("No", "Yes"), .rows = structure(list(1:2, 3:4), ptype = integer(0), class = c(
    "vctrs_vctr", "list"
), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, -2L), .drop = TRUE))

It looks like this:


I want it to look like this:


How do I do it, please, ?

This works for your example

data1 %>% 
  arrange(Soccer_type, desc(Arthritis))

# A tibble: 4 × 3
# Groups:   Arthritis [2]
  Arthritis Soccer_type     N
  <chr>     <chr>       <int>
1 Yes       Elite          10
2 No        Elite          61
3 Yes       Non_Elite       9
4 No        Non_Elite     206


Thank you very much indeed.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.