Back to Course

R for Busy People (Cohort-0)

0% Complete
0/0 Steps
  1. Installing R and RStudio
    1 Lesson
    |
    2 Quizzes
  2. The RStudio IDE
    1 Lesson
    |
    2 Quizzes
  3. Coding Basics
    1 Lesson
    |
    2 Quizzes
  4. Assignment | Workshop 1
    1 Quiz
  5. Data dive: Ebola in Sierra Leone
    1 Lesson
    |
    2 Quizzes
  6. RStudio Projects
    1 Lesson
    |
    2 Quizzes
  7. Workshop 2
    1 Lesson
    |
    1 Quiz
  8. Using R Markdown
    1 Lesson
    |
    2 Quizzes
  9. Data classes & structures (deprec)
    2 Lessons
  10. Workshop 3
    1 Lesson
    |
    1 Quiz
  11. Select & rename
    1 Lesson
    |
    3 Quizzes
  12. Filter
    1 Lesson
    |
    3 Quizzes
  13. Workshop 4
    1 Quiz
  14. Mutate
    1 Lesson
    |
    3 Quizzes
  15. Workshop 5
    1 Lesson
    |
    1 Quiz
  16. Conditional mutate
    1 Lesson
    |
    3 Quizzes
  17. Group by and summarize
    1 Lesson
    |
    2 Quizzes
  18. Workshop 6
    1 Lesson
    |
    1 Quiz
  19. Other grouped operations
    1 Lesson
    |
    2 Quizzes
  20. Workshop 7
    1 Lesson
    |
    1 Quiz
  21. Intro to ggplot2
    1 Lesson
    |
    2 Quizzes
  22. Scatter plots and smoothing
    1 Lesson
    |
    2 Quizzes
  23. Workshop 8
    1 Lesson
    |
    1 Quiz
  24. Lines, scales, and labels
    1 Lesson
    |
    2 Quizzes
  25. Overview of the EpiGraphHub web platform
  26. Data exploration on EpiGraphHub
    1 Quiz
  27. Workshop 9
    1 Lesson
    |
    1 Quiz
  28. Workshop 10
    1 Lesson
    |
    1 Quiz
  29. Final project
    1 Lesson
    |
    1 Quiz
  30. Getting help
    1 Lesson
    |
    1 Quiz
  31. Quiz contributions
    16 Lessons
Topic 17 of 31
In Progress

Group by and summarize

🚗 Video too fast or too slow? Click the gear icon ⚙️ at the bottom-right to change the speed!


Lesson code

Please download the zip folder below to code along with the instructor.

You need to unzip this folder to code along. Or “Extract All” on Windows. See our video explanation of this if you are unsure.


Lesson notes

The written guide below is an accompaniment to the lesson video. You may read through it if you prefer written tutorials to video content.

Subscribe
Notify of
guest

15 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
Samuel

data quiz question: Could someone explain why I have Cov=4.2 instead of 0.015 ? Please see my codes below. covid_well_being_1 <- covid_well_being |> mutate(sleep_time=minutes_from_sleep_to_wake – minutes_awake_at_night) covid_well_being_1 sleep_time_and_stress <-  covid_well_being_1 %>% group_by(respondent_id) %>% summarize (mean_sleep_time = mean(sleep_time, na.rm = T), mean_stress_levels = mean(stress_1_low_7_high, na.rm = T) ) sleep_time_and_stress  sleep_time_and_stress |> signif(digits = 3) cov(x=sleep_time_and_stress$mean_sleep_time, y=sleep_time_and_stress$mean_stress_levels) |>… Read more »

Cicilia Gita

Hi Samuel, I think it may be because you use cov () instead of cor (). I looked at chatGPT and it says cor () is used to compute the correlation coefficient between variables while cov () is used to compute the covariance between variables. Please try with cor () as we are… Read more »

Last edited 2 months ago by Cicilia Gita
Joy

Nice catch, Cicilia!

Joy

Samuel, apart from the small typo in your function name that Cicilia mentioned, your code looks good to me. I hope you are able to try the suggested solution and resolve the issue.

Samuel

Joy, thank you. I have resolved the issue thanks to Cicilia. However, I have already submitted the data quiz and missed the related question.

Cicilia Gita

Dear Tutor, could you please advise if we should use ungroup () function systematically after the group_by () and summarize () functions are being used? Thank you.

Joy

Hi Cicilia, good question. If you intend to use your summarized data frame for further manipulations — e.g., with mutate() or select() — you should add ungroup() after group_by() and summarize(), otherwise it will likely produce errors down the line. However, if you are creating a summary table which you don’t plan to… Read more »

Cicilia Gita

Thanks for this advice, Joy. Very useful.

Samuel

Hello Team. Could anyone explain why the question check said this is incorrect ?

Q_sum_bedridden_days <- 
 yao %>% group_by(sex) %>% summarize(total_bedridden_days = sum(n_days_miss_work, na.rm = TRUE))
 Q_sum_bedridden_days  

Cicilia Gita

Hi Samuel, from your code, I could see that you use variable n_days_miss_work to calculate total bedridded_days. That’s why it’s incorrect. You may want to use n_bedridden_days instead.

Samuel

thank you. Resolved

Axel

Requesting a support for the quiz on this lesson Dear Graph Team, I would ask a support from you about this quiz. I have done this quiz and I got 142,1% and I click on button “send” for submit it. We tell me that it’s submitted and it told me that I got… Read more »

Axel

Now the problem is resolved

Aba

Hello, please there seems to be a problem with how the system is checking the answers to the questions.

15
0
Questions or comments?x