Basic Quiz Set

Q1. (group_by)

아래 데이터프레임에서 성별(Gender)로 그룹을 묶으세요.

library(tibble)
library(dplyr)
## 
## 다음의 패키지를 부착합니다: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
df <- tibble(
  Customer_ID = 1:6,
  Gender = c("Male", "Female", "Female", "Male", "Male", "Female"),
  Total_Spend = c(100000, 150000, 200000, 120000, 170000, 130000)
)

Q2. (summarise)

위에서 만든 그룹에서 성별별 총 구매금액 합계를 구하세요.

  • 힌트: sum() 함수를 사용합니다.

Q3. (mutate)

고객별로 구매금액이 150,000 이상이면 “High”, 미만이면 “Low”라는 새로운 변수를 추가하세요.

  • 힌트: ifelse()를 사용합니다.

Intermediate Quiz Set

Q4. (group_by + summarise 복합)

지역(Region)별로 가장 많은 구매횟수(Purchase_Frequency)의 평균을 구하세요.

df <- tibble(
  Customer_ID = 1:8,
  Region = c("Seoul", "Busan", "Seoul", "Gwangju", "Busan", "Daejeon", "Seoul", "Busan"),
  Purchase_Frequency = c(3, 5, 2, 4, 6, 2, 7, 3)
)
  • 어떤 기준으로 묶고?
  • 어떤 통계를 구할지 고민하세요.

Q5. (mutate + case_when 고급)

나이에 따라 다음과 같이 새로운 열을 추가하세요. (Age_Group)

  • 18~29세 → “Youth”
  • 30~49세 → “Adult”
  • 50세 이상 → “Senior”
df <- tibble(
  Customer_ID = 1:6,
  Age = c(22, 35, 47, 52, 28, 61)
)
  • 힌트: case_when()을 사용합니다.

Advanced Quiz Set

Q6. (group_by + summarise + mutate 콤보)

주어진 데이터에서: - 데이터를 병합합 - 지역별로 총 구매금액 합계를 구하고 - 합계가 400,000 이상이면 “Top Region”, 아니면 “Normal Region”으로 구분하는 열을 추가하세요.


library(tibble)
library(dplyr)

df1 <- tibble(
  Customer_ID = 1:6,
  Gender = c("Male", "Female", "Female", "Male", "Male", "Female"),
  Total_Spend = c(100000, 150000, 200000, 120000, 170000, 130000)
)


df2 <- tibble(
  Customer_ID = 1:6,
  Region = c("Seoul", "Busan", "Seoul", "Gwangju", "Busan", "Daejeon"),
  Purchase_Frequency = c(3, 5, 2, 4, 6, 2)
)