Stratified Sampling and Cluster Sampling - R

Screen Link:
https://app.dataquest.io/c/70/m/394/stratified-sampling-and-cluster-sampling/3/creating-and-analyzing-strata-with-dplyr

Seems like there has been an update to the dplyr package that raises a warning when using the summarise() function that is causing an error with the answer checking. The following code should work but it raises a warning that triggers the answer checking system to say the code causes an error:

set.seed(1)

wnba <- wnba %>%
        mutate(
            pts_game = PTS / Games_Played
            )

total_points_estimates <- wnba %>%
                          group_by(Pos) %>%
                          sample_n(10) %>%
                          summarise(
                              mean_pts_season = mean(PTS),
                              mean_pts_game = mean(pts_game)
                          ) %>%
                          arrange(Pos)

Warning message: summarise() ungrouping output (override with .groups argument)

I was able to submit and get correct answer by passing .groups='drop'. This code does not produce the warning and is marked as a pass by the grading system:

set.seed(1)

wnba <- wnba %>%
        mutate(
            pts_game = PTS / Games_Played
            )

total_points_estimates <- wnba %>%
                          group_by(Pos) %>%
                          sample_n(10) %>%
                          summarise(
                              mean_pts_season = mean(PTS),
                              mean_pts_game = mean(pts_game),
                              .groups='drop'
                          ) %>%
                          arrange(Pos)
1 Like