Arrange () desc() and ascending is not working at all tried multiple ways

Dear All,

I am New to R & Rstudio, I have done a case study for my Google certification, I faced no issues at all during that case study and then after I have decided to work on more case studies and I took dataset of World development report from Data catalog of World Bank.

I have created a .csv with four indicators that explains the statistics of women life expectancy, in order to create plots and as well visualizations on tableau so that can sum up as a simple and quick case study and I have tried various ways to arrange the dataset and create a new data frame comparing the countries that took interest over the area of women life expectancy and the countries that did not contributed for the improvement of women life expectancy

the below code is just one of method I have tried, results of both data frames are identical whereas expected results should be different, I have tried various other ways as well, ungrouping and etc, I do not want to share that code because it would occupy unnecessary space.

Kindly shed your light

I am loading the below packages every time I work
library(tidyr)
library(tidyverse)
library(janitor)
library(readxl)
library(ggplot2)
library(skimr)
library(dplyr)


unsupportive_countries_women <- new_women_life_summary %>%
  filter(
    Indicator_Name %in% c(
      "Adolescent fertility rate (births per 1,000 women ages 15-19)",      
      "Mortality rate, adult, female (per 1,000 female adults)",
      "Population ages 15-19, female (% of female population)",
      "Population ages 15-64, female (% of female population)",
      "Population growth (annual %)"
    )
  ) %>%
  group_by(Country_Name, Country_code, Indicator_Name, Indicator_code) %>%
  arrange(as.numeric(min(Mean_Value_1960_to_2022), min(Median_Value_1960_to_2022), min(Maximum_Value_1961_to_2022), min(Minimum_Value_1960_to_2022))) %>%
  head(50)


# Filter countries with highest mean and max for selected indicators
supportive_countries_women <- new_women_life_summary %>%
  filter(
    Indicator_Name %in% c(
      "Mortality rate, adult, female (per 1,000 female adults)",
      "Population ages 15-19, female (% of female population)",
      "Population ages 15-64, female (% of female population)",
      "Population growth (annual %)"
    )
  ) %>%
  group_by(Country_Name, Country_code, Indicator_Name, Indicator_code) %>%
  arrange(
    desc(Mean_Value_1960_to_2022), 
    desc(Median_Value_1960_to_2022), 
    desc(Maximum_Value_1961_to_2022), 
    desc(Minimum_Value_1960_to_2022)) %>%
  head(50)

from the documentation of arrange, which you can read by sending ?arrange to your console

Unlike other dplyr verbs, arrange() largely ignores grouping; you need to explicitly mention grouping variables (or use .by_group = TRUE )

Thanks for the reply, I will try accordingly.

This topic was automatically closed 21 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.