🚗 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.
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 »
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 »
Nice catch, Cicilia!
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.
Joy, thank you. I have resolved the issue thanks to Cicilia. However, I have already submitted the data quiz and missed the related question.
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.
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 »
Thanks for this advice, Joy. Very useful.
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
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.
thank you. Resolved
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 »
Now the problem is resolved
Hello, please there seems to be a problem with how the system is checking the answers to the questions.
Sorry about the issue! This has now been fixed. Thanks for noticing.