You are the walrus
Getting a column name like `median(perc_electric_access, na.rm = TRUE)` in the previous lesson can be pretty difficult to work with as a programmer. In this exercise, you'll use the walrus operator (:=) and other rlang magic with dplyr to specify the name of that column instead.
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Programming with dplyr
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Finish the function definition
grouped_median_for_column <- function(.data, group_col, col_to_median) {
name_of_col_to_median <- ___(enquo(col_to_median))
new_col_name <- paste0("median_of_", name_of_col_to_median)
.data %>%
group_by( ___ ) %>%
summarize(___new_col_name ___ median( ___ ,
na.rm = TRUE))
}