< 분석도전 >
-
Q1. ggplot2의 midwest 데이터를 데이터 프레임 형태로 불러온 다음 데이터의 특징을 파악하세요
-
Q2. poptotal 변수를 total로, popasian 변수를 asian으로 수정하세요
-
Q3. total, asian 변수를 이용해 '전체 인구 대비 아시아 인구 백분율' 파생변수를 만들고 히스토그램을 만들어 도시들이 어떻게 분포하는지 살펴보세요
-
Q4. 아시아 인구 백분율 전체 평균을 구하고, 평균을 초과하면 "large", 그 외에는 "small"을 부여하는 파생변수를 만들어 보세요
-
Q5. "large"와 "small"에 해당하는 지역이 얼마나 되는지 빈도표와 빈도 막대 그래프를 만들어 확인해보세요.
# Q1
library(ggplot2)
df <- as.data.frame(ggplot2::midwest)
head(df)
View(df)
str(df)
summary(df)
# Q2
library(dplyr)
df <- rename(df, total=poptotal)
df <- rename(df, asian=popasian)
head(df)
# Q3
df$ratio_asianpertotal <- (df$asian/df$total)*100
hist(df$ratio_asianpertotal)
# Q4
mean_asian <- mean(df$ratio_asianpertotal)
mean_asian
df$ratio_asianpertotal_test <- ifelse( df$ratio_asianpertotal > mean_asian, "large", "small")
head(df)
# Q5
table(df$ratio_asianpertotal_test)
qplot(df$ratio_asianpertotal_test)
[ ⅰ. 데이터 파악하기 ]
head() | tail() | View() | dim() | str() | summary() |
데이터 앞부분 | 데이터 뒷부분 | 뷰어 창에 출력 | 데이터 차원 | 데이터 속성 | 요약 통계량 |
[ⅱ. 변수명 바꾸기]
- df <- rename(df, 바꿀 변수이름 = df에 있는 변수 이름)
[ ⅲ. 파생변수 ]
- df$신규변수 <- 수식
- df$신규변수 <- ifelse(조건식, 조건일치時, 조건불일치時)
[ ⅳ. 빈도확인 ]
- table()
- hist()
- qplot()
'데이터 분석 > R' 카테고리의 다른 글
Part ⅩⅠ: 지도 시각화 (0) | 2021.01.11 |
---|---|
Part Ⅹ: 텍스트 마이닝 (0) | 2021.01.11 |
Part Ⅸ: 한국 복지 패널 데이터 분석 (0) | 2021.01.07 |
Part Ⅷ: 데이터 시각화 (0) | 2021.01.07 |
Part Ⅶ: 데이터 정제(결측치 / 이상치) (0) | 2021.01.07 |
Part Ⅵ: 데이터 전처리 (0) | 2021.01.06 |