๋ฐ์ดํฐ ์ฌ์ด์ธ์ค 100๋ฒ์ ๋ ธํฌ(๊ตฌ์กฐํ ๋ฐ์ดํฐ ์ฒ๋ฆฌํธ) โ R Part 5 (Q81 to Q100)์ ํด์ค์ ๋๋ค.
ย
์ฐธ๊ณ (Reference) : ใ๋ฐ์ดํฐ ์ฌ์ด์ธํฐ์คํธ ํํ ์คํฌ ์ ์ ์์ใ์ ใ๋ฐ์ดํฐ ์ฌ์ด์ธ์ค 100๋ฒ์ ๋ ธํฌ(๊ตฌ์กฐํ ๋ฐ์ดํฐ ์ฒ๋ฆฌํธ)ใ์ ๋๋ค.
์ฒ์์
- ๋จผ์ ๋ค์ ์ ์ ์คํํฉ๋๋ค.
- ํ์ํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๊ฐ์ ธ์ค๊ณ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์ ๋ฐ์ดํฐ๋ฅผ ์ฝ์ต๋๋ค(PostgreSQL).
- ์ฌ์ฉํ ๊ฒ์ผ๋ก ์์๋๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ ๋ค์ ์ ์์ ๊ฐ์ ธ์ต๋๋ค.
- ์ฌ์ฉํ๋ ค๋ ๋ค๋ฅธ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์๋ ๊ฒฝ์ฐ install.packages()๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ ํ๊ฒ ์ค์นํฉ๋๋ค.
- ์ด๋ฆ, ์ฃผ์ ๋ฑ์ ๋๋ฏธ ๋ฐ์ดํฐ์ด๋ฉฐ ์ค์ ๋ฐ์ดํฐ๊ฐ ์๋๋๋ค.
require("RPostgreSQL")
require("tidyr")
require("dplyr")
require("stringr")
require("caret")
require("lubridate")
require("rsample")
require("recipes")
require("themis")
host <- "db"
port <- Sys.getenv()["PG_PORT"]
dbname <- Sys.getenv()["PG_DATABASE"]
user <- Sys.getenv()["PG_USER"]
password <- Sys.getenv()["PG_PASSWORD"]
con <- dbConnect(PostgreSQL(), host=host, port=port, dbname=dbname, user=user, password=password)
df_customer <- dbGetQuery(con,"SELECT * FROM customer")
df_category <- dbGetQuery(con,"SELECT * FROM category")
df_product <- dbGetQuery(con,"SELECT * FROM product")
df_receipt <- dbGetQuery(con,"SELECT * FROM receipt")
df_store <- dbGetQuery(con,"SELECT * FROM store")
df_geocode <- dbGetQuery(con,"SELECT * FROM geocode")
Loading required package: RPostgreSQL Loading required package: DBI Loading required package: tidyr Loading required package: dplyr Attaching package: โdplyrโ The following objects are masked from โpackage:statsโ: filter, lag The following objects are masked from โpackage:baseโ: intersect, setdiff, setequal, union Loading required package: stringr Loading required package: caret Loading required package: ggplot2 Loading required package: lattice Loading required package: lubridate Attaching package: โlubridateโ The following objects are masked from โpackage:baseโ: date, intersect, setdiff, union Loading required package: rsample Loading required package: recipes Attaching package: โrecipesโ The following object is masked from โpackage:stringrโ: fixed The following object is masked from โpackage:statsโ: step Loading required package: themis Registered S3 methods overwritten by 'themis': method from bake.step_downsample recipes bake.step_upsample recipes prep.step_downsample recipes prep.step_upsample recipes tidy.step_downsample recipes tidy.step_upsample recipes tunable.step_downsample recipes tunable.step_upsample recipes Attaching package: โthemisโ The following objects are masked from โpackage:recipesโ: step_downsample, step_upsample
ย
์ฐ์ต๋ฌธ์
R-081: ๋จ๊ฐ(unit_price)์ ์๊ฐ(unit_cost)์ ๊ฒฐ์๊ฐ์ ๋ํด ๊ฐ๊ฐ์ ํ๊ท ๊ฐ์ผ๋ก ๋ณด์ํ ์๋ก์ด ์ํ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ์์ค. ๋จ, ํ๊ท ๊ฐ์ 1์ ๋ฏธ๋ง์ ๋ฐ์ฌ๋ฆผํ๋ค(๋ฐ์ฌ๋ฆผ ๋๋ ์ง์๋ก ๋ฐ์ฌ๋ฆผํด๋ ๋ฌด๋ฐฉํ๋ค). ๋ณด์ ์ค์ ํ ๊ฐ ํญ๋ชฉ์ ๋ํด ๊ฒฐ์์ด ๋ฐ์ํ์ง ์์๋์ง๋ ํ์ธํด์ผ ํ๋ค.
price_mean <- round(mean(df_product$unit_price, na.rm = TRUE))
cost_mean <- round(mean(df_product$unit_cost, na.rm = TRUE))
df_product_2 <- df_product %>%
replace_na(list(unit_price = price_mean, unit_cost = cost_mean))
sapply(df_product_2, function(x) sum(is.na(x)))
- product_cd
- 0
- category_major_cd
- 0
- category_medium_cd
- 0
- category_small_cd
- 0
- unit_price
- 0
- unit_cost
- 0
ย
์ค๋ช :
์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ๋์์ ํ๋ค.
๋ฐ์ดํฐ ํ๋ ์ 'df_product'์ 'unit_price'์ 'unit_cost' ์ด์ ํ๊ท ์ ๊ณ์ฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์๋ก ๋ฐ์ฌ๋ฆผํ๋ค.
price_mean <- round(mean(df_product$unit_price, na.rm = TRUE)) cost_mean <- round(mean(df_product$unit_cost, na.rm = TRUE))
round() ํจ์๋ ํ๊ท ๊ฐ์ ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์๋ก ๋ฐ์ฌ๋ฆผํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
na.rm=TRUE๋ ๊ณ์ฐ์์ ๊ฒฐ์๊ฐ์ ์ ๊ฑฐํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ค.
df_product'์ 'unit_price'์ 'unit_cost' ์ด์ ๊ฒฐ์๊ฐ์ ๊ฐ๊ฐ์ ํ๊ท ๊ฐ์ผ๋ก ๋์ฒดํ๋ค.
df_product_2 <- df_product %>% replace_na(list(unit_price = price_mean, unit_cost = cost_mean))
replace_na()๋ 'tidyr' ํจํค์ง์์ ๊ฒฐ์๋ ๊ฐ์ ์์ ๊ณ์ฐํ ํ๊ท ๊ฐ์ผ๋ก ๋์ฒดํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
์ฐ์ฐ์ %>%(ํ์ดํ ์ฐ์ฐ์๋ผ๊ณ ๋ ํจ)๋ ๋ ๊ฐ์ ์ก์ ์ ํจ๊ป ์ฐ๊ฒฐํ๋ ๋ฐ ์ฌ์ฉ๋๋ฉฐ, ์ฒซ ๋ฒ์งธ ์ก์ ์ ์ถ๋ ฅ์ ๋ ๋ฒ์งธ ์ก์ ์ ์ ๋ ฅ์ผ๋ก ์ฌ์ฉ๋๋ค.
sapply() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์์ ํ 'df_product_2' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์์ ๋๋ฝ๋ ๊ฐ์ ์๋ฅผ ๊ณ์ฐํ๋ค.
sapply(df_product_2, function(x) sum(is.na(x)))
sapply() ํจ์๋ 'df_product_2' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์ ํจ์(function(x) sum(is.na(x)))๋ฅผ ์ ์ฉํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
ํจ์์ sum(is.na(x)) ๋ถ๋ถ์ 'df_product_2' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด(x)์์ ๋๋ฝ๋ ๊ฐ(NA)์ ์๋ฅผ ๊ณ์ฐํ๋ค.
R-082: ๋จ๊ฐ(unit_price)์ ์๊ฐ(unit_cost)์ ๊ฒฐ์๊ฐ์ ๋ํด ๊ฐ๊ฐ์ ์ค์๊ฐ์ผ๋ก ๋ณด์ํ ์๋ก์ด ์ํ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ์์ค. ๋จ, ์ค์๊ฐ์ 1์ ๋ฏธ๋ง์ ๋ฐ์ฌ๋ฆผํ๋ค(๋ฐ์ฌ๋ฆผ ๋๋ ์ง์๋ก ๋ฐ์ฌ๋ฆผํด๋ ๋ฌด๋ฐฉํ๋ค). ๋ณด์ ์ค์ ํ ๊ฐ ํญ๋ชฉ์ ๋ํด ๊ฒฐ์์ด ๋ฐ์ํ์ง ์์๋์ง๋ ํ์ธํด์ผ ํ๋ค.
price_median <- round(median(df_product$unit_price, na.rm = TRUE))
cost_median <- round(median(df_product$unit_cost, na.rm = TRUE))
df_product_3 <- df_product %>%
replace_na(list(unit_price = price_median, unit_cost = cost_median))
sapply(df_product_3, function(x) sum(is.na(x)))
- product_cd
- 0
- category_major_cd
- 0
- category_medium_cd
- 0
- category_small_cd
- 0
- unit_price
- 0
- unit_cost
- 0
์ค๋ช :
์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ๋์์ ์ํํ๋ค.
๋ฐ์ดํฐ ํ๋ ์ 'df_product'์ 'unit_price'์ 'unit_cost' ์ด์ ์ค์๊ฐ์ ๊ณ์ฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์๋ก ๋ฐ์ฌ๋ฆผํ๋ค.
price_median <- round(median(df_product$unit_price, na.rm = TRUE)) cost_median <- round(median(df_product$unit_cost, na.rm = TRUE))
median() ํจ์๋ 'unit_price' ๋ฐ 'unit_cost' ์ด์ ์ค์๊ฐ์ ๊ณ์ฐํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
round() ํจ์๋ ์ค์๊ฐ์ ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์๋ก ๋ฐ์ฌ๋ฆผํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
na.rm=TRUE๋ ๊ณ์ฐ์์ ๋๋ฝ๋ ๊ฐ์ ์ ๊ฑฐํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
df_product'์ 'unit_price' ๋ฐ 'unit_cost' ์ปฌ๋ผ์ ๊ฒฐ์๋ ๊ฐ์ ๊ฐ๊ฐ์ ์ค์๊ฐ์ผ๋ก ๋์ฒดํ๋ค.
df_product_3 <- df_product %>% replace_na(list(unit_price = price_median, unit_cost = cost_median))
replace_na()๋ 'tidyr' ํจํค์ง์ ๊ฒ์ผ๋ก, ๊ฒฐ์๋ ๊ฐ์ ์์ ๊ณ์ฐํ ์ค์๊ฐ์ผ๋ก ๋์ฒดํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
์ฐ์ฐ์ %>%(ํ์ดํ ์ฐ์ฐ์๋ผ๊ณ ๋ ํจ)๋ฅผ ์ฌ์ฉํ์ฌ ๋ ๊ฐ์ ์ก์ ์ ์ฐ๊ฒฐํ๊ณ ์ฒซ ๋ฒ์งธ ์ก์ ์ ์ถ๋ ฅ์ ๋ ๋ฒ์งธ ์ก์ ์ ์ ๋ ฅ์ผ๋ก ์ฌ์ฉํฉ๋๋ค.
sapply() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์์ ๋ 'df_product_3' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์์ ๋๋ฝ๋ ๊ฐ์ ์๋ฅผ ๊ณ์ฐํ๋ค.
sapply(df_product_3, function(x) sum(is.na(x)))
sapply() ํจ์๋ 'df_product_3' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์ ํจ์(function(x) sum(is.na(x)))๋ฅผ ์ ์ฉํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
ํจ์์ sum(is.na(x)) ๋ถ๋ถ์ 'df_product_3' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด(x)์์ ๋๋ฝ๋ ๊ฐ(NA)์ ์๋ฅผ ๊ณ์ฐํ๋ค.
R-083: ๋จ๊ฐ(unit_price)์ ์๊ฐ(unit_cost)์ ๊ฒฐ์๊ฐ์ ๋ํด ๊ฐ ์ํ์ ์นดํ ๊ณ ๋ฆฌ ์๋ถ๋ฅ ์ฝ๋(category_small_cd)๋ณ๋ก ์ฐ์ถํ ์ค๊ฐ๊ฐ์ผ๋ก ๋ณด์ํ ์๋ก์ด ์ํ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ๋ค. ๋จ, ์ค์๊ฐ์ 1์ ๋ฏธ๋ง์ ๋ฐ์ฌ๋ฆผํ๋ค(๋ฐ์ฌ๋ฆผ ๋๋ ์ง์๋ก ๋ฐ์ฌ๋ฆผํด๋ ๋ฌด๋ฐฉํ๋ค). ๋ณด์ ์ค์ ํ ๊ฐ ํญ๋ชฉ์ ๋ํด ๊ฒฐ์์ด ๋ฐ์ํ์ง ์์๋์ง๋ ํ์ธํด์ผ ํ๋ค.
df_product_4 <- df_product %>%
group_by(category_small_cd) %>%
summarise(price_median = round(median(unit_price, na.rm = TRUE)), cost_median = round(median(unit_cost, na.rm = TRUE)), .groups = "drop") %>%
inner_join(df_product, by = "category_small_cd") %>%
mutate(unit_price = ifelse(is.na(unit_price), price_median, unit_price), unit_cost = ifelse(is.na(unit_cost), cost_median, unit_cost)) sapply(df_product_4, function(x) sum(is.na(x)))
- category_small_cd
- 0
- price_median
- 0
- cost_median
- 0
- product_cd
- 0
- category_major_cd
- 0
- category_medium_cd
- 0
- unit_price
- 0
- unit_cost
- 0
ย
์ค๋ช :
์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ๋์์ ํ๋ค.
'df_product' ๋ฐ์ดํฐ ํ๋ ์์ 'category_small_cd' ์ปฌ๋ผ์ผ๋ก ๊ทธ๋ฃนํํ๋ค.
df_product_4 <- df_product %>% group_by(category_small_cd)
์ฐ์ฐ์ %>%๋ ๋ ๊ฐ์ ์ก์ ์ ์ฐ๊ฒฐํ๊ธฐ ์ํด ์ฌ์ฉ๋๋ฉฐ, ์ฒซ ๋ฒ์งธ ์ก์ ์ ์ถ๋ ฅ์ ๋ ๋ฒ์งธ ์ก์ ์ ์ ๋ ฅ์ผ๋ก ์ฌ์ฉ๋๋ค.
'dplyr' ํจํค์ง์ 'group_by()' ํจ์๋ฅผ ์ฌ์ฉํ์ฌ 'df_product' ๋ฐ์ดํฐ ํ๋ ์์ 'category_small_cd' ์ด๋ก ๊ทธ๋ฃนํํ๋ค.
๊ทธ๋ฃนํ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ๊ทธ๋ฃน์ 'unit_price' ๋ฐ 'unit_cost' ์ด์ ์ค์๊ฐ์ ๊ณ์ฐํ๊ณ , ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์๋ก ๋ฐ์ฌ๋ฆผํ์ฌ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ผ๋ก ์์ฝํ๋ค.
summarise(price_median = round(median(unit_price, na.rm = TRUE)), cost_median = round(median(unit_cost, na.rm = TRUE)), .groups = "drop")
'summarise()' ํจ์๋ 'dplyr' ํจํค์ง์์ ์ฌ์ฉํ๋ฉฐ, ๊ทธ๋ฃนํํ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ๊ทธ๋ฃน์ 'unit_price'์ 'unit_cost' ์ด์ ์ค์๊ฐ์ ์ฐ์ถํ๋ค.
'round()' ํจ์๋ ์ค์๊ฐ์ ๊ฐ์ฅ ๊ฐ๊น์ด ์ ์๋ก ๋ฐ์ฌ๋ฆผํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
na.rm=TRUE๋ ๊ณ์ฐ์์ ๋๋ฝ๋ ๊ฐ์ ์ ๊ฑฐํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
.groups="drop" ์ธ์๋ ์ถ๋ ฅ์์ ๊ทธ๋ฃนํ ์ ๋ณด๋ฅผ ์ ๊ฑฐํ๋ ๋ฐ ์ฌ์ฉ๋ฉ๋๋ค.
์์ฝ๋ ๋ฐ์ดํฐ ํ๋ ์๊ณผ ์๋์ 'df_product' ๋ฐ์ดํฐ ํ๋ ์์ 'category_small_cd' ์ปฌ๋ผ์ผ๋ก ๊ฒฐํฉํ๋ค.
inner_join(df_product, by = "category_small_cd")
'inner_join()' ํจ์๋ 'dplyr' ํจํค์ง์์ ์ฌ์ฉ๋๋ฉฐ, 'category_small_cd' ์ด์ ์ํด ์์ฝ ๋ฐ์ดํฐ ํ๋ ์๊ณผ ์๋์ 'df_product' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฒฐํฉํ๋ค.
๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๋ชจ๋ ์ด์ ๋ชจ๋ ๊ฐ๊ฒ ๋๋ค.
๊ฒฐํฉ๋ ๋ฐ์ดํฐ ํ๋ ์์ 'unit_price' ๋ฐ 'unit_cost' ์ด์ ๋๋ฝ๋ ๊ฐ์ ํด๋น 'category_small_cd' ๊ทธ๋ฃน์ ๊ฐ ์ค์๊ฐ์ผ๋ก ๋์ฒดํฉ๋๋ค.
mutate(unit_price = ifelse(is.na(unit_price), price_median, unit_price), unit_cost = ifelse(is.na(unit_cost), cost_median, unit_cost))
'mutate()' ํจ์๋ 'dplyr' ํจํค์ง์์ ๊ฒฐํฉ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ์ ๋ณ๊ฒฝํ ์๋ก์ด ์ด์ ์์ฑํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
ifelse() ํจ์๋ 'unit_price'์ 'unit_cost' ์ด์์ ๊ฐ์ด ๋๋ฝ(NA)๋์ด ์๋์ง ํ์ธํ๊ณ , ํด๋น ๊ฐ์ด ์ํ 'category_small_cd' ๊ทธ๋ฃน์ ํด๋น ์ค๊ฐ๊ฐ์ผ๋ก ๋์ฒดํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
sapply() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ณ๊ฒฝ ํ 'df_product_4' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์์ ๋๋ฝ๋ ๊ฐ์ ๊ฐ์๋ฅผ ๊ณ์ฐํ๋ค.
sapply(df_product_4, function(x) sum(is.na(x)))
sapply() ํจ์๋ 'df_product_4' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์ ํจ์(function(x) sum(is.na(x)))๋ฅผ ์ ์ฉํ๋ ๋ฐ ์ฌ์ฉ๋๋ค.
ํจ์์ sum(is.na(x)) ๋ถ๋ถ์ 'df_product_4' ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด(x)์์ ๋๋ฝ๋ ๊ฐ(NA)์ ์๋ฅผ ๊ณ์ฐํ๋ค.
R-084: ๊ณ ๊ฐ ๋ฐ์ดํฐ(df_customer)์ ์ ์ฒด ๊ณ ๊ฐ์ ๋ํด ์ ์ฒด ๊ธฐ๊ฐ์ ๋งค์ถ ๊ธ์ก์์ 2019๋ ๋งค์ถ ๊ธ์ก์ด ์ฐจ์งํ๋ ๋น์จ์ ๊ณ์ฐํ์ฌ ์๋ก์ด ๋ฐ์ดํฐ๋ฅผ ์์ฑํ๋ค. ๋จ, ๋งค์ถ ์ค์ ์ด ์๋ ๊ฒฝ์ฐ 0์ผ๋ก ์ฒ๋ฆฌํ๋ค. ๊ทธ๋ฆฌ๊ณ ๊ณ์ฐํ ๋น์จ์ด 0์ ์ด๊ณผํ๋ ๊ฒ์ ์ถ์ถํ์ฌ ๊ฒฐ๊ณผ๋ฅผ 10๊ฑด์ฉ ํ์ํ๋ผ. ๋ํ, ์์ฑ๋ ๋ฐ์ดํฐ์ ๊ฒฐ์์ด ์๋์ง ํ์ธํ๋ผ.
df_receipt_2019 <- df_receipt %>%
filter(20190101 <= sales_ymd & sales_ymd <= 20191231) %>%
group_by(customer_id) %>% summarise(amount_2019 = sum(amount), .groups = "drop")
df_receipt_all <- df_receipt %>%
group_by(customer_id) %>%
summarise(amount_all = sum(amount), .groups = "drop")
df_sales_rate <- left_join(df_customer["customer_id"], df_receipt_2019, by = "customer_id") %>%
left_join(df_receipt_all, by = "customer_id") %>%
replace_na(list(amount_2019 = 0, amount_all = 0)) %>%
mutate(amount_rate = ifelse(amount_all == 0, 0, amount_2019 / amount_all)) df_sales_rate %>% filter(amount_rate > 0) %>%
slice(1:10)
customer_id | amount_2019 | amount_all | amount_rate |
---|---|---|---|
<chr> | <dbl> | <dbl> | <dbl> |
CS031415000172 | 2971 | 5088 | 0.58392296 |
CS015414000103 | 874 | 3122 | 0.27994875 |
CS011215000048 | 248 | 3444 | 0.07200929 |
CS029415000023 | 3767 | 5167 | 0.72904974 |
CS035415000029 | 5823 | 7504 | 0.77598614 |
CS023513000066 | 208 | 771 | 0.26977951 |
CS035513000134 | 463 | 1565 | 0.29584665 |
CS001515000263 | 216 | 216 | 1.00000000 |
CS006415000279 | 229 | 229 | 1.00000000 |
CS031415000106 | 215 | 7741 | 0.02777419 |
sapply(df_receipt_2019, function(x) sum(is.na(x)))
- customer_id
- 0
- amount_2019
- 0
์ค๋ช :
์ด ์ฝ๋์์๋ df_receipt๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๋ํด ๋ช ๊ฐ์ง ๋ฐ์ดํฐ ์กฐ์์ ํ๊ณ ์๋๋ฐ, ์ด ๋ฐ์ดํฐ ํ๋ ์์๋ ๋งค์ถ ๊ฑฐ๋์ ๋ํ ์ ๋ณด๊ฐ ํฌํจ๋์ด ์์ ๊ฒ์ผ๋ก ์ถ์ ๋๋ค. ์๋๋ ๊ฐ ์ฝ๋์ ๊ฐ ํ์ด ๋ฌด์์ ํ๊ณ ์๋์ง๋ฅผ ๋ถ์ํ ๋ด์ฉ์ ๋๋ค.
df_receipt_2019 <- df_receipt %>% filter(20190101 <= sales_ymd & sales_ymd <= 20191231) %>% group_by(customer_id) %>% summise(amount_2019 = sum( amount), .groups = "drop")
์ด ์ฝ๋ ๋ผ์ธ์ df_receipt_2019๋ผ๋ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํ๊ณ , ์๋์ df_receipt ๋ฐ์ดํฐ ํ๋ ์์ ํํฐ๋งํ์ฌ 2019๋ 1์ 1์ผ๋ถํฐ 2019๋ 12์ 31์ผ ์ฌ์ด์ ๋ฐ์ํ ํ๋งค ๊ฑฐ๋๋ง ํฌํจํ๋๋ก ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ customer_id๋ก ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋ฃนํํ์ฌ ํด๋น ๊ธฐ๊ฐ ๋์ ๊ฐ ๊ณ ๊ฐ์ด ์ฌ์ฉํ ๊ธ์ก์ ํฉ๊ณ๋ฅผ ๊ณ์ฐํ๊ณ ๊ฒฐ๊ณผ๋ฅผ amount_2019๋ผ๋ ์๋ก์ด ์ด์ ์ ์ฅํฉ๋๋ค.
df_receipt_all <- df_receipt %>% group_by(customer_id) %>% summise(amount_all = sum(amount), .groups = "drop")
์ด ์ฝ๋์์๋ df_receipt_all์ด๋ผ๋ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํ๊ณ , df_receipt ๋ฐ์ดํฐ ํ๋ ์์ customer_id๋ก ๊ทธ๋ฃนํํ์ฌ ๊ฐ ๊ณ ๊ฐ์ด ๋ชจ๋ ๊ฑฐ๋์์ ์ฌ์ฉํ ์ด ๊ธ์ก์ ๊ณ์ฐํ์ฌ ๊ฒฐ๊ณผ๋ฅผ amount_all์ด๋ผ๋ ์๋ก์ด ์ด์ ์ ์ฅํ๊ณ ์์ต๋๋ค.
df_sales_rate <- left_join(df_customer["customer_id"], df_receipt_2019, by = "customer_id") %>% left_join(df_receipt_all, by = "customer_id") %>% replace_na(list(quantity_2019 = 0, amount_all = 0)) %>% mutate(amount_rate = ifelse(amount_all == 0, 0, amount_2019 / amount_all)) %>% filter( amount_rate > 0) %>% slice(1: 10)
์ด ์ฝ๋์์๋ df_customer ๋ฐ์ดํฐ ํ๋ ์(๊ณ ๊ฐ์ ์์ฑ์ ๋ํ ์ ๋ณด๋ฅผ ๋ด๊ณ ์์ ๊ฐ๋ฅ์ฑ์ด ๋์)๊ณผ df_receipt_2019 ๋ฐ df_receipt_all ๋ฐ์ดํฐ ํ๋ ์์ customer_id ์ด๋ก ๊ฒฐํฉํ์ฌ df_sales_rate๋ผ๋ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํ๊ณ ์์ต๋๋ค. ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํฉ๋๋ค. ๊ทธ๋ฐ ๋ค์ amount_2019์ amount_all ์ด์ ๊ฒฐ์๊ฐ์ 0์ผ๋ก ๋์ฒดํ๊ณ , 2019๋ ์ ๋ฐ์ํ ๊ณ ๊ฐ ์ด ์ง์ถ์ ๋น์จ์ ๋ํ๋ด๋ amount_rate๋ผ๋ ์๋ก์ด ์ด์ ๊ณ์ฐํ์ฌ(์ฆ, amount_2019 / amount_all) 2019๋ ์ ๋์ ์ด ๊ณ ๊ฐ๋ง ํฌํจํ๋๋ก ๋ฐ์ดํฐ๋ฅผ ํํฐ๋งํฉ๋๋ค. (์ฆ, amount_rate > 0)์ผ๋ก ๋ฐ์ดํฐ๋ฅผ ํํฐ๋งํ๊ณ , ๋ง์ง๋ง์ผ๋ก amount_rate ๊ฐ์ ๋ฐ๋ผ ์์ 10๋ช ์ ๊ณ ๊ฐ์ ์ ํํ๋ค(์ฆ, slice(1:10)).
์ ์ฒด์ ์ผ๋ก ์ด ์ฝ๋๋ 2019๋ ์ ์ด ์ง์ถ ๋น์จ์ด ๊ฐ์ฅ ๋์ ์์ 10๋ช ์ ๊ณ ๊ฐ์ ์๋ณํ์ฌ ํ๊ฒ ๋ง์ผํ ๋ฐ ๊ณ ๊ฐ ์ ์ง ๋ ธ๋ ฅ์ ๋์์ด ๋ ๊ฒ์ผ๋ก ๋ณด์ธ๋ค.
R-085: ๊ณ ๊ฐ ๋ฐ์ดํฐ(df_customer)์ ๋ชจ๋ ๊ณ ๊ฐ์ ๋ํด ์ฐํธ๋ฒํธ(postal_cd)๋ฅผ ์ด์ฉํ์ฌ ์ง์ค์ฝ๋ ๋ฐ์ดํฐ(df_geocode)๋ฅผ ์ฐ๊ฒฐํ์ฌ ์๋ก์ด ๊ณ ๊ฐ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ๋ค. ๋จ, ํ๋์ ์ฐํธ๋ฒํธ(postal_cd)์ ์ฌ๋ฌ ๊ฐ์ ๊ฒฝ๋(longitude), ์๋(latitude) ์ ๋ณด๊ฐ ์ฐ๊ฒฐ๋ ๊ฒฝ์ฐ์๋ ๊ฒฝ๋(longitude), ์๋(latitude)์ ํ๊ท ๊ฐ์ ์ฐ์ถํ์ฌ ์ฌ์ฉํด์ผ ํ๋ค. ๋ํ, ์์ฑ๋ ๊ฒฐ๊ณผ๋ฅผ ํ์ธํ๊ธฐ ์ํด 10๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ํ์ํ๋ค.
df_geocode_1 <- df_geocode[c("postal_cd", "longitude" ,"latitude")] %>% group_by(postal_cd) %>%
summarise(m_longiture = mean(longitude), m_latitude = mean(latitude), .groups = "drop")
df_customer_1 <- inner_join(df_customer, df_geocode_1, by = "postal_cd") head(df_customer_1, 10)
ย | customer_id | customer_name | gender_cd | gender | birth_day | age | postal_cd | address | application_store_cd | application_date | status_cd | m_longiture | m_latitude |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ย | <chr> | <chr> | <chr> | <chr> | <date> | <int> | <chr> | <chr> | <chr> | <chr> | <chr> | <dbl> | <dbl> |
1 | CS021313000114 | ๅคง้ ใใๅญ | 1 | ๅฅณๆง | 1981-04-29 | 37 | 259-1113 | ็ฅๅฅๅท็ไผๅขๅๅธ็ฒ็ชช********** | S14021 | 20150905 | 0-00000000-0 | 139.3178 | 35.41358 |
2 | CS037613000071 | ๅ ญ่ง ้ ๅฝฆ | 9 | ไธๆ | 1952-04-01 | 66 | 136-0076 | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ********** | S13037 | 20150414 | 0-00000000-0 | 139.8350 | 35.67193 |
3 | CS031415000172 | ๅฎๅค็ฐ ่ฒด็พๅญ | 1 | ๅฅณๆง | 1976-10-04 | 42 | 151-0053 | ๆฑไบฌ้ฝๆธ่ฐทๅบไปฃใ ๆจ********** | S13031 | 20150529 | D-20100325-C | 139.6897 | 35.67374 |
4 | CS028811000001 | ๅ ไบ ใใใ | 1 | ๅฅณๆง | 1933-03-27 | 86 | 245-0016 | ็ฅๅฅๅท็ๆจชๆตๅธๆณๅบๅๆณ็บ********** | S14028 | 20160115 | 0-00000000-0 | 139.4836 | 35.39125 |
5 | CS001215000145 | ็ฐๅด ็พ็ด | 1 | ๅฅณๆง | 1995-03-29 | 24 | 144-0055 | ๆฑไบฌ้ฝๅคง็ฐๅบไปฒๅ ญ้ท********** | S13001 | 20170605 | 6-20090929-2 | 139.7078 | 35.54084 |
6 | CS020401000016 | ๅฎฎไธ ้ๅฃซ | 0 | ็ทๆง | 1974-09-15 | 44 | 174-0065 | ๆฑไบฌ้ฝๆฟๆฉๅบ่ฅๆจ********** | S13020 | 20150225 | 0-00000000-0 | 139.6724 | 35.77073 |
7 | CS015414000103 | ๅฅฅ้ ้ฝๅญ | 1 | ๅฅณๆง | 1977-08-09 | 41 | 136-0073 | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ********** | S13015 | 20150722 | B-20100609-B | 139.8360 | 35.67818 |
8 | CS029403000008 | ้ ไบบๅฟ | 0 | ็ทๆง | 1973-08-17 | 45 | 279-0003 | ๅ่็ๆตฆๅฎๅธๆตทๆฅฝ********** | S12029 | 20150515 | 0-00000000-0 | 139.9047 | 35.65422 |
9 | CS015804000004 | ๆพ่ฐท ็ฑณ่ต | 0 | ็ทๆง | 1931-05-02 | 87 | 136-0073 | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ********** | S13015 | 20150607 | 0-00000000-0 | 139.8360 | 35.67818 |
10 | CS033513000180 | ๅฎๆ ้ฅ | 1 | ๅฅณๆง | 1962-07-11 | 56 | 241-0823 | ็ฅๅฅๅท็ๆจชๆตๅธๆญๅบๅ้จ็บ********** | S14033 | 20150728 | 6-20080506-5 | 139.5146 | 35.45013 |
์ค๋ช :
์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ์์ ์ ์ํํ๋ค.
df_geocode ๋ฐ์ดํฐ ํ๋ ์์์ 3๊ฐ์ ์ด(postal_cd, longitude, latitude)์ ์ ํํ์ฌ df_geocode_1์ด๋ผ๋ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํ๋ค.
df_geocode_1 ๋ฐ์ดํฐ ํ๋ ์์ postal_cd๋ก ๊ทธ๋ฃนํ๋๋ฉฐ, ๊ฐ ๊ทธ๋ฃน์ ๊ฒฝ๋์ ์๋์ ํ๊ท ๊ฐ์ด summarise() ํจ์๋ก ๊ณ์ฐ๋๋ค. ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ postal_cd์ ๊ณ ์ ํ ๊ฐ๋ง๋ค ํ ์ค, postal_cd, m_longitude, m_latitude์ ์ด์ ํฌํจํ๋ค.
df_customer ๋ฐ์ดํฐ ํ๋ ์์ ๊ณตํต postal_cd ์ด์ ๊ธฐ์ค์ผ๋ก ํ์ ์ผ์น์ํค๋ inner_join() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ df_geocode_1 ๋ฐ์ดํฐ ํ๋ ์๊ณผ ๊ฒฐํฉ๋๋ค. ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๋ชจ๋ ์ด์ ํฌํจํ๋ค.
head() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์(df_customer_1)์ ์ฒ์ 10๊ฐ์ ํ์ ํ์ํ๋ค. ์ด ํ์๋ ๊ณ ๊ฐ์ ๋ํ ์ ๋ณด์ ์ง๋ฆฌ์ ์์น(์๋ ๋ฐ ๊ฒฝ๋)๊ฐ ํฌํจ๋์ด ์์ต๋๋ค.
S-086: 085์์ ์์ฑํ ์๋๊ฒฝ๋๋ณ ๊ณ ๊ฐ ๋ฐ์ดํฐ์ ๋ํด ํ์ ์ ์ฒญ ๋งค์ฅ ์ฝ๋(application_store_cd)๋ฅผ ํค๋ก ๋งค์ฅ ๋ฐ์ดํฐ(df_store)์ ๊ฒฐํฉํ๋ผ. ๊ทธ๋ฆฌ๊ณ ์ ์ฒญ ๋งค์ฅ์ ์๋(latitude)-๊ฒฝ๋ ์ ๋ณด(longitude)์ ๊ณ ๊ฐ ์ฃผ์(address)์ ์๋-๊ฒฝ๋๋ฅผ ์ด์ฉํ์ฌ ์ ์ฒญ ๋งค์ฅ๊ณผ ๊ณ ๊ฐ ์ฃผ์์ ๊ฑฐ๋ฆฌ(๋จ์: km)๋ฅผ ๊ตฌํ๊ณ , ๊ณ ๊ฐ ID(customer_id), ๊ณ ๊ฐ ์ฃผ์(address), ๋งค์ฅ ์ฃผ์(address)์ ํจ๊ป ํ์ํ๋ผ. ๊ณผ ํจ๊ป ํ์ํ๋ผ. ๊ณ์ฐ์์ ์๋์ ๊ฐ๋จํ ์์ ์ฌ์ฉํ๋, ๊ทธ ์ธ ์ ๋ฐ๋๊ฐ ๋์ ๋ฐฉ์์ ์ด์ฉํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฌ์ฉํด๋ ๋ฌด๋ฐฉํ๋ค. ๊ฒฐ๊ณผ๋ 10๊ฑด์ ํ์ํ๋ค.
์๋๏ผ๋ผ๋์๏ผ๏ผฯ๊ฒฝ๋๏ผ๋ผ๋์๏ผ๏ผฮป:๊ฑฐ๋ฆฌL=6371โarccosโก(sinโกฯ1โsinฯ2+cosโกฯ1โcosโกฯ2โcosโก(ฮป1โฮป2))
calc_distance <- function(x1, y1, x2, y2) { distance <- 6371 * acos( sin(x1 * pi / 180) * sin(x2 * pi / 180) + cos(x1 * pi / 180) * cos(x2 * pi / 180) * cos((y1 * pi / 180) - (y2 * pi / 180 ))) print(class(distance)) # Check the CLASS of the calculation results just to be sure. return(distance) }
inner_join(df_customer_1, df_store, by = c("application_store_cd" = "store_cd")) %>%
rename(customer_address = address.x, store_address = address.y) %>%
mutate(distance = calc_distance(m_latitude, m_longiture, latitude, longitude)) %>% select(customer_id, customer_address, store_address, distance) %>%
slice(1:10)
[1] "numeric"
customer_id | customer_address | store_address | distance |
---|---|---|---|
<chr> | <chr> | <chr> | <dbl> |
CS021313000114 | ็ฅๅฅๅท็ไผๅขๅๅธ็ฒ็ชช********** | ็ฅๅฅๅท็ไผๅขๅๅธไผๅขๅๅไธ็ฎ | 1.3944087 |
CS037613000071 | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ********** | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ไธไธ็ฎ | 1.4511822 |
CS031415000172 | ๆฑไบฌ้ฝๆธ่ฐทๅบไปฃใ ๆจ********** | ๆฑไบฌ้ฝๆธ่ฐทๅบๅๅฐไบไธ็ฎ | 0.4117335 |
CS028811000001 | ็ฅๅฅๅท็ๆจชๆตๅธๆณๅบๅๆณ็บ********** | ็ฅๅฅๅท็ๆจชๆตๅธ็ฌ่ฐทๅบไบใๆฉ็บ | 8.0651960 |
CS001215000145 | ๆฑไบฌ้ฝๅคง็ฐๅบไปฒๅ ญ้ท********** | ๆฑไบฌ้ฝๅคง็ฐๅบไปฒๅ ญ้ทไบไธ็ฎ | 1.2684210 |
CS020401000016 | ๆฑไบฌ้ฝๆฟๆฉๅบ่ฅๆจ********** | ๆฑไบฌ้ฝๅๅบๅๆกไปฒๅไธไธ็ฎ | 4.1859046 |
CS015414000103 | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ********** | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ไบไธ็ฎ | 1.4496734 |
CS029403000008 | ๅ่็ๆตฆๅฎๅธๆตทๆฅฝ********** | ๅ่็ๆตฆๅฎๅธๆฑ้ไธไธ็ฎ | 0.8048581 |
CS015804000004 | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ********** | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ไบไธ็ฎ | 1.4496734 |
CS033513000180 | ็ฅๅฅๅท็ๆจชๆตๅธๆญๅบๅ้จ็บ********** | ็ฅๅฅๅท็ๆจชๆตๅธ็ฌ่ฐทๅบ้ฟไน ๅ่ฅฟไธไธ็ฎ | 1.9569470 |
์ค๋ช :
์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ์์ ์ ์ํํ๋ค.
calc_distance()๋ผ๋ ์ฌ์ฉ์ ์ ์ ํจ์๋ฅผ ์ ์ํ๊ณ 4๊ฐ์ ๋งค๊ฐ๋ณ์ x1, y1, y1, x2, y2๋ฅผ ๋ฐ๋๋ค. ์ด ํจ์๋ ๋ ์ง๋ฆฌ์ ์์น(์๋์ ๊ฒฝ๋๋ก ์ง์ ) ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ฅผ ํ๋ฒ์ ์ ๊ณต์์ ์ฌ์ฉํ์ฌ ๊ณ์ฐํ๋ค. ๊ณ์ฐ๋ ๊ฑฐ๋ฆฌ๋ ํฌ๋ก๋ฏธํฐ ๋จ์๋ก ๋ฐํ๋๋ค.
df_customer_1 ๋ฐ์ดํฐ ํ๋ ์์ inner_join() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ df_store ๋ฐ์ดํฐ ํ๋ ์๊ณผ ๊ฒฐํฉํ๋ค. ๊ฒฐํฉ์ df_customer_1์ application_store_cd ์ด๊ณผ df_store์ store_cd ์ด์ ๋ํด ์ํ๋๋ค.
๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ rename() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ ๊ฐ์ ์๋ก ๋ค๋ฅธ ์ฃผ์ ์ปฌ๋ผ์ ๋ฐ์ํ๋๋ก ์ด๋ฆ์ด ๋ณ๊ฒฝ๋๋ค.
mutate() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ distance๋ผ๋ ์๋ก์ด ์ด์ด ์ถ๊ฐ๋๋ฉฐ, calc_distance() ํจ์๋ ๊ณ ๊ฐ๊ณผ ๋งค์ฅ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๋ฅผ ๊ณ์ฐํ๋ ๋ฐ ์ฌ์ฉ๋๋ค. ์ด ํจ์๋ df_customer_1์ ์๋์ ๊ฒฝ๋์ ํ๊ท ๊ฐ(m_latitude์ m_longitude)๊ณผ df_store์ ์๋์ ๊ฒฝ๋ ๊ฐ์ด๋ผ๋ 4๊ฐ์ ์ธ์๋ก ํธ์ถ๋๋ค. ์ป์ด์ง ๊ฑฐ๋ฆฌ ๊ฐ์ distance ์ด์ ์ ์ฅ๋๋ค.
๋ค์์ผ๋ก select() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ customer_id, customer_address, store_address, distance ์ด๋ง ํฌํจํ๋๋ก ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ ์๋ธ์ ํ๋ค.
๋ง์ง๋ง์ผ๋ก slice() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ ์ฒ์ 10๊ฐ์ ํ์ ํ์ํ๋ค. ์ด ํ์๋ ๊ณ ๊ฐ์ ๋ํ ์ ๋ณด, ๊ณ ๊ฐ ์ฃผ์, ๋งค์ฅ ์ฃผ์, ๊ณ ๊ฐ๊ณผ ๋งค์ฅ ์ฌ์ด์ ๊ฑฐ๋ฆฌ๊ฐ ํฌํจ๋์ด ์๋ค.
R-087: ๊ณ ๊ฐ ๋ฐ์ดํฐ(df_customer)์๋ ๋ค๋ฅธ ๋งค์ฅ์์์ ์ ์ฒญ ๋ฑ์ผ๋ก ๋์ผ ๊ณ ๊ฐ์ด ์ฌ๋ฌ ๊ฐ ๋ฑ๋ก๋์ด ์๋ค. ์ด๋ฆ(customer_name)๊ณผ ์ฐํธ๋ฒํธ(postal_cd)๊ฐ ๊ฐ์ ๊ณ ๊ฐ์ ๋์ผ ๊ณ ๊ฐ์ผ๋ก ๊ฐ์ฃผํ์ฌ 1๊ณ ๊ฐ 1๋ ์ฝ๋๊ฐ ๋๋๋ก ์ด๋ฆ์ ๋ถ์ธ ๋ช ๋ชฉ ๊ณ ๊ฐ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ๊ณ , ๊ณ ๊ฐ ๋ฐ์ดํฐ ๊ฐ์, ๋ช ๋ชฉ ๊ณ ๊ฐ ๋ฐ์ดํฐ ๊ฐ์, ์ค๋ณต ํ์๋ฅผ ๊ณ์ฐํ๋ผ. ๋จ, ๋์ผ ๊ณ ๊ฐ์ ๋ํด์๋ ๋งค์ถ ๊ธ์ก ํฉ๊ณ๊ฐ ๊ฐ์ฅ ๋์ ๊ฒ์ ๋จ๊ธฐ๊ณ , ๋งค์ถ ๊ธ์ก ํฉ๊ณ๊ฐ ๋์ผํ๊ฑฐ๋ ๋งค์ถ ์ค์ ์ด ์๋ ๊ณ ๊ฐ์ ๋ํด์๋ ๊ณ ๊ฐ ID(customer_id)์ ๋ฒํธ๊ฐ ์์ ๊ฒ์ ๋จ๊ธด๋ค.
df_sales_amount <- df_receipt %>%
group_by(customer_id) %>% summarise(sum_amount = sum(amount), .groups = "drop")
df_customer_u <- left_join(df_customer, df_sales_amount, by = "customer_id") %>% mutate(sum_amount = ifelse(is.na(sum_amount), 0, sum_amount)) %>% arrange(desc(sum_amount), customer_id) %>%
distinct(customer_name, postal_cd, .keep_all = TRUE)
print(paste( "df_customer_cnt:", nrow(df_customer), "df_customer_u_cnt:", nrow(df_customer_u), "diff:", nrow(df_customer) - nrow(df_customer_u)))
[1] "df_customer_cnt: 21971 df_customer_u_cnt: 21941 diff: 30"
์ค๋ช :
์ด ์ฝ๋๋ ๋ค์ ๋จ๊ณ๋ฅผ ์ํํ๋ค.
df_receipt ๋ฐ์ดํฐ ํ๋ ์์์ ๊ฐ ๊ณ ๊ฐ์ ๋งค์ถ ๊ธ์ก์ ํฉ๊ณ๋ฅผ ๊ณ์ฐํ๊ณ group_by()์ summarise() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์ df_sales_amount์ ๊ฒฐ๊ณผ๋ฅผ ์ ์ฅํฉ๋๋ค.
df_sales_amount <- df_receipt %>% group_by(customer_id) %>% summise(sum_amount = sum(amount), .groups = "drop")
customer_id ์ปฌ๋ผ์ ๊ธฐ์ค์ผ๋ก df_customer์ df_sales_amount ๋ฐ์ดํฐ ํ๋ ์ ๊ฐ ์ข๊ฒฐํฉ์ ์ํํ๊ณ , mutate() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ sum_amount ์ปฌ๋ผ์ NA ๊ฐ์ 0์ผ๋ก ๋ฐ๊พธ๊ณ , ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ sum_amount์ customer_id์ ๋ด๋ฆผ์ฐจ์์ผ๋ก ์ ๋ ฌํ๊ณ , customer_name๊ณผ portal_cd ์ปฌ๋ผ์ ๊ธฐ์ค์ผ๋ก ๊ณ ์ ํ ํ๋ง ์ ์งํ๋ค.
df_customer_u <- left_join(df_customer, df_sales_amount, by = "customer_id") %>% mutate(sum_amount = ifelse(is.na(sum_amount), 0, sum_amount) %>% arrange(desc(sum_amount), customer_id) %>% distinct(customer_name, postal_cd, .keep_all = TRUE)
์๋ณธ df_customer ๋ฐ์ดํฐ ํ๋ ์, ๊ฒฐ๊ณผ df_customer_u ๋ฐ์ดํฐ ํ๋ ์์ ํ ์์ ๊ทธ ์ฐจ์ด๋ฅผ ์ถ๋ ฅํ์ฌ ์ค๋ณต๋ ํ์ด ์ผ๋ง๋ ์ญ์ ๋์๋์ง ํ์ธํ๋ค.
print(paste( "df_customer_cnt:", nrow(df_customer), "df_customer_u_cnt:", nrow(df_customer_u), "diff:", nrow(df_customer) - nrow(df_ customer_u))))
R-088: 087์์ ์์ฑํ ๋ฐ์ดํฐ๋ฅผ ๋ฐํ์ผ๋ก ๊ณ ๊ฐ ๋ฐ์ดํฐ์ ํตํฉ๋ช ์นญ ID๋ฅผ ๋ถ์ฌํ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ๋ค. ๋จ, ํตํฉ๋ช ์นญ ID๋ ์๋์ ์ฌ์์ผ๋ก ๋ถ์ฌํ๋ค.
- ์ค๋ณต๋์ง ์์ ๊ณ ๊ฐ : ๊ณ ๊ฐ ID(customer_id) ์ค์
- ์ค๋ณต๋๋ ๊ณ ๊ฐ: ์ด์ ์ค๋ฌธ์์ ์ถ์ถํ ๋ ์ฝ๋์ ๊ณ ๊ฐ ID๋ฅผ ์ค์ ํ๋ค.
๊ณ ๊ฐ ID์ ๊ณ ์ ๊ฑด์์ ํตํฉ๋ช ์นญ ID์ ๊ณ ์ ๊ฑด์ ์ฐจ์ด๋ ํ์ธํด์ผ ํ๋ค.
df_customer_n = inner_join(df_customer,
df_customer_u[c("customer_id","customer_name","postal_cd")],
by = c("customer_name", "postal_cd")) %>%
rename(customer_id = customer_id.x,
integration_id = customer_id.y)
customer_id_cnt <- length(unique(df_customer_n$customer_id))
integration_id_cnt <- length(unique(df_customer_n$integration_id))
print(paste("Difference in number of IDs", customer_id_cnt - integration_id_cnt))
[1] "ID์์ ์ฐจ์ด 30"
์ค๋ช :
์ด ์ฝ๋๋ ๋ค์๊ณผ ๊ฐ์ ์์ ์ ์ํํ๋ค.
df_customer์ df_customer_u ์ฌ์ด์์ "customer_name"๊ณผ "postal_cd"๋ผ๋ ์ปฌ๋ผ์ ๊ฒฐํฉ ํค๋ก ์ฌ์ฉํ์ฌ ๋ด๋ถ ๊ฒฐํฉ์ ์ํํฉ๋๋ค.
๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ df_customer_n์ ํ ๋น๋ฉ๋๋ค.
df_customer_n์ "customer_id.x" ์ด์ "customer_id"๋ก ์ด๋ฆ์ด ๋ณ๊ฒฝ๋ฉ๋๋ค.
df_customer_u์ "customer_id.y" ์ด์ "integration_id"๋ก ์ด๋ฆ์ ๋ฐ๊พผ๋ค.
df_customer_n์ "customer_id"์ "integration_id"์ด์ ๊ณ ์ ๊ฐ์ ์๋ฅผ ๊ณ์ฐํ๊ณ ์ด ์์ ์ฐจ์ด๋ฅผ ์ถ๋ ฅํ๋ค.
์ด ์ฝ๋์ ๋ชฉ์ ์ ์๋ df_customer ๋ฐ์ดํฐ ํ๋ ์์ ๊ณ ์ ํ ๊ณ ๊ฐ ID ์์ df_customer์ ๊ณ ๊ฐ๋ณ ์ด ๋งค์ถ ๊ธ์ก(df_sales_amount)์ ๊ฒฐํฉํ์ฌ ๋ง๋ df_customer_u ๋ฐ์ดํฐ ํ๋ ์์ ๊ณ ์ ํ ๊ณ ๊ฐ ID ์์ ๋น๊ต ํ๋ ๊ฒ์ ๋๋ค. ์ ์ ์กฐ๊ฑด์ผ๋ก df_customer์๋ ๊ณ ๊ฐ ์ด๋ฆ๊ณผ ์ฐํธ๋ฒํธ๊ฐ ์ค๋ณต๋ ์ ์์ผ๋ฏ๋ก df_customer์ ๊ณ ์ ํ ๊ณ ๊ฐ ID ์๊ฐ df_customer_u์ ๋นํด ๋ ๋ง์ ๊ฒ์ด๋ค. ์ฝ๋ ๋์ ํ์๋๋ ๋ ์นด์ดํธ์ ์ฐจ์ด๋ ๊ฒฐํฉ ์์ ์ ํตํด ์ญ์ ๋ ์ค๋ณต๋ ๊ณ ๊ฐ ID์ ์๋ฅผ ๋ํ๋ ๋๋ค.
R-089: ์์ธก ๋ชจ๋ธ ๊ตฌ์ถ์ ์ํด ํ๋งค ์ค์ ์ด ์๋ ๊ณ ๊ฐ์ ํ์ต์ฉ ๋ฐ์ดํฐ์ ํ ์คํธ์ฉ ๋ฐ์ดํฐ๋ก ๋๋๊ณ ์ถ๋ค. ๊ฐ๊ฐ 8:2์ ๋น์จ๋ก ๋ฌด์์๋ก ๋ฐ์ดํฐ๋ฅผ ๋ถํ ํ๋ผ.
set.seed(71)
#Example using rsample initial_split
df_sales_customer <- df_receipt %>%
group_by(customer_id) %>%
summarise(sum_amount = sum(amount), .groups = "drop") %>%
filter(sum_amount > 0)
df_tmp <- inner_join(df_customer, df_sales_customer, by = "customer_id")
split <- initial_split(df_tmp, prop = 0.8) df_customer_train <- training(split) df_customer_test <- testing(split)
# ็ขบ่ช
print(paste("Percentage of training data:", nrow(df_customer_train) / nrow(df_tmp))) print(paste("Test Data Percentage:", nrow(df_customer_test) / nrow(df_tmp)))
[1] " ํ์ต ๋ฐ์ดํฐ ๋น์จ ": 0.799903684083795"
[1] " ํ
์คํธ ๋ฐ์ดํฐ ๋น์จ " : 0.200096315916205"
์ค๋ช :
์ด ์ฝ๋๋ R์ rsample ํจํค์ง๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ ์ธํธ๋ฅผ ํ๋ จ ์ธํธ์ ํ ์คํธ ์ธํธ๋ก ๋๋๋ค.
set.seed(71)๋ ๊ฒฐ๊ณผ์ ์ฌํ์ฑ์ ๋ณด์ฅํ๊ธฐ ์ํด ๋ฌด์์ ์๋๋ฅผ ์ค์ ํ๋ค.
df_sales_customer๋ df_receipt๋ฅผ customer_id๋ก ๊ทธ๋ฃนํํ์ฌ ๊ฐ ๊ณ ๊ฐ์ ๊ธ์ก ํฉ๊ณ๋ฅผ ๊ณ์ฐํ์ฌ ๋ง๋ค์ด์ง๋ค. ๊ทธ๋ฆฌ๊ณ ํฉ๊ณ๊ฐ ํ๋ฌ์ค๊ฐ ๋๋ ๊ณ ๊ฐ๋ง ๋จ๊ธด๋ค.
df_tmp๋ df_customer์ df_sales_customer๋ฅผ customer_id๋ก ๊ฒฐํฉํ์ฌ ๋ง๋ค์ด์ง๋ค.
split์ rsample ํจํค์ง์ initial_split() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์์ฑํ๋ฉฐ, prop ํ๋ผ๋ฏธํฐ๋ 0.8๋ก ์ค์ ๋์ด ์์ด ๋ฐ์ดํฐ ์งํฉ์ด 80%์ ํ๋ จ ๋ฐ์ดํฐ์ 20%์ ํ ์คํธ ๋ฐ์ดํฐ๋ก ๋ถํ ๋จ์ ์๋ฏธํ๋ค.
df_customer_train๊ณผ df_customer_test๋ ๊ฐ๊ฐ ๋ถํ ์ ํตํด ์ป์ ํ๋ จ ์ธํธ์ ํ ์คํธ ์ธํธ์ด๋ค.
๋ง์ง๋ง์ผ๋ก print() ๋ฌธ์ผ๋ก ํ๋ จ ๋ฐ์ดํฐ์ ํ ์คํธ ๋ฐ์ดํฐ์ ๋น์จ์ ํ์ธํ๋ค.
R-090: ์์์ฆ ๋ด์ญ ๋ฐ์ดํฐ(df_receipt)๋ 2017๋ 1์ 1์ผ๋ถํฐ 2019๋ 10์ 31์ผ๊น์ง์ ๋ฐ์ดํฐ๋ฅผ ๊ฐ์ง๊ณ ์๋ค. ๋งค์ถ ๊ธ์ก(amount)์ ์๋ณ๋ก ์ง๊ณํ์ฌ ํ์ต์ฉ 12๊ฐ์, ํ ์คํธ์ฉ 6๊ฐ์์ ์๊ณ์ด ๋ชจ๋ธ ๊ตฌ์ถ์ฉ ๋ฐ์ดํฐ 3์ธํธ๋ฅผ ์์ฑํ๋ค.
#caret์ createTimeSlices๋ฅผ ์ฌ์ฉํ ์์
df_ts_amount <- df_receipt %>% group_by(substr(as.character(sales_ymd), 1, 6)) %>% summarise(sum_amount = sum(amount), .groups = "drop")
colnames(df_ts_amount) <- c("sales_ym", "sales_amount")
timeSlice <- createTimeSlices(df_ts_amount$sales_ym, initialWindow = 12, horizon = 6, skip = 5, fixedWindow = TRUE)
df_train_1 <- df_ts_amount[timeSlice$train[[1]],]
df_train_2 <- df_ts_amount[timeSlice$train[[2]],]
df_train_3 <- df_ts_amount[timeSlice$train[[3]],]
df_test_1 <- df_ts_amount[timeSlice$test[[1]],]
df_test_2 <- df_ts_amount[timeSlice$test[[2]],]
df_test_3 <- df_ts_amount[timeSlice$test[[3]],]
# df_train_2์ df_train_3์ ํ์๋ ์๋ต df_train_1
sales_ym | sales_amount |
---|---|
<chr> | <int> |
201701 | 902056 |
201702 | 764413 |
201703 | 962945 |
201704 | 847566 |
201705 | 884010 |
201706 | 894242 |
201707 | 959205 |
201708 | 954836 |
201709 | 902037 |
201710 | 905739 |
201711 | 932157 |
201712 | 939654 |
# df_test_2์ df_test_3์ ํ์ ์๋ต df_test_1
sales_ym | sales_amount |
---|---|
<chr> | <int> |
201801 | 944509 |
201802 | 864128 |
201803 | 946588 |
201804 | 937099 |
201805 | 1004438 |
201806 | 1012329 |
์ค๋ช :
์ด ์ฝ๋๋ care ํจํค์ง์ createTimeSlices ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์๊ฐ ๊ธฐ๋ฐ ๊ต์ฐจ ๊ฒ์ฆ ํด๋๋ฅผ ์์ฑํ๋ ๋ฐฉ๋ฒ์ ์์ด๋ค.
์ด ์ฝ๋์ ์ฒซ ๋ฒ์งธ ๋จ๊ณ๋ group_by ํจ์์ summarise ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ ์ฒด ๋ฐ์ดํฐ ์ธํธ์ ์๋ณ ๋งค์ถ ๊ธ์ก์ ์์ฝํ๋ ๊ฒ์ด๋ค. ๊ทธ๋ฆฌ๊ณ ์์ฑ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๋ณด๋ค ์๋ฏธ ์๋ ์ปฌ๋ผ ์ด๋ฆ์ผ๋ก ์ด๋ฆ์ด ๋ณ๊ฒฝ๋๋ค.
๊ทธ๋ฐ ๋ค์ createTimeSlices ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ์ ๋ํด 3๊ฐ์ ์๊ฐ ๊ธฐ๋ฐ ํด๋ฉ์ ์์ฑํฉ๋๋ค. ์ด ํจ์๋ ์์ ๋ฒกํฐ(์ด ๊ฒฝ์ฐ ํ๋งค ์)๋ฅผ ๋ฐ์ ๊ฐ ํด๋์ ํธ๋ ์ด๋ ์ธ๋ฑ์ค์ ํ ์คํธ ์ธ๋ฑ์ค ์ธํธ๋ก ๋๋๋ค. initialWindow ๋งค๊ฐ ๋ณ์๋ ์ฒซ ๋ฒ์งธ ํธ๋ ์ด๋ ์๋์ฐ์ ํฌ๊ธฐ๋ฅผ, horizon ๋งค๊ฐ ๋ณ์๋ ํ ์คํธ ์๋์ฐ์ ํฌ๊ธฐ๋ฅผ, skip ๋งค๊ฐ๋ณ์๋ ๊ฐ ํด๋ ์ฌ์ด์ ๊ฑด๋๋ฐ๋ ์๊ฐ ์์, fixedWindow ๋งค๊ฐ๋ณ์๋ ํ ์คํธ ์๋์ฐ์ ํฌ๊ธฐ๋ฅผ ๊ณ ์ ์ํฌ์ง ์ฌ๋ถ๋ฅผ ์ง์ ํ๋ค.
๋ง์ง๋ง์ผ๋ก createTimeSlices์์ ์์ฑ๋ ์ธ๋ฑ์ค๋ฅผ ์ฌ์ฉํ์ฌ df_train๊ณผ df_test ๋ฐ์ดํฐ ํ๋ ์์ด ๊ฐ ๋ฉ์์ ์์ฑ๋๋ค. ์ด ๋ฐ์ดํฐ ํ๋ ์์ ๋ชจ๋ธ์ ์๊ฐ ๊ธฐ๋ฐ ๊ต์ฐจ ๊ฒ์ฆ์ ์ฌ์ฉํ ์ ์๋ค.
ย
R-091: ๊ณ ๊ฐ ๋ฐ์ดํฐ(df_customer)์ ๊ฐ ๊ณ ๊ฐ์ ๋ํด ๋งค์ถ ์ค์ ์ด ์๋ ๊ณ ๊ฐ ์์ ๋งค์ถ ์ค์ ์ด ์๋ ๊ณ ๊ฐ ์๊ฐ 1:1์ด ๋๋๋ก ์ธ๋์ํ๋ง์ผ๋ก ์ถ์ถํ๋ผ.
#receipts ํจํค์ง ์ฌ์ฉ ์์
df_sales_amount <- df_receipt %>%
group_by(customer_id) %>%
summarise(sum_amount = sum(amount), .groups = "drop") %>%
right_join(df_customer, by = "customer_id") %>%
mutate(is_buy_flag = factor(ifelse(is.na(sum_amount), 0, 1)))
df_down_sampling <- df_sales_amount %>%
recipe() %>%
step_downsample(is_buy_flag, seed = 71) %>%
prep() %>% juice()
df_down_sampling %>%
group_by(is_buy_flag) %>%
summarise(cnt = n(), .groups = "drop")
is_buy_flag | cnt |
---|---|
<fct> | <int> |
0 | 8306 |
1 | 8306 |
์ค๋ช :
R์ recipes ํจํค์ง๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ด์ํ๋ง์ ์คํํ๋ ์ฝ๋์ ๋๋ค.
๋จผ์ ๊ฐ ๊ณ ๊ฐ์ ๋งค์ถ ๊ธ์ก์ ํฉ๊ณ๋ฅผ ๊ณ์ฐํ์ฌ ๊ณ ๊ฐ ์ ๋ณด์ ๊ฒฐํฉํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ is_buy_flag๋ผ๋ ๋ฐ์ด๋๋ฆฌ ๋ณ์๋ฅผ ์์ฑํ์ฌ ํ๋งค ๊ธ์ก์ ์ ๋ฌด๋ก ๊ณ ๊ฐ์ด ๊ตฌ๋งคํ๋์ง ์ฌ๋ถ๋ฅผ ๋ํ๋ ๋๋ค.
๋ค์์ผ๋ก recipe() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ ์ํผ ๊ฐ์ฒด๋ฅผ ์์ฑํ๋ค. ๊ทธ๋ฐ ๋ค์ step_downsample() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ 71๊ฐ์ ๋ฌด์์ ์๋๋ฅผ ์ฌ์ฉํ์ฌ ๋ค์ ํด๋์ค(๊ตฌ๋งคํ์ง ์์ ๊ณ ๊ฐ)๋ฅผ ์์ ํด๋์ค(๊ตฌ๋งคํ ๊ณ ๊ฐ)์ ๊ด์ฐฐ ์์ ๋ง๊ฒ ๋ค์ด์ํ๋งํ๋ค.
prep() ํจ์๋ ๋ ์ํผ ์ค๋น์, juice() ํจ์๋ ์ฒ๋ฆฌ๋ ๋ฐ์ดํฐ ์ธํธ์ ์ถ์ถ์ ์ฌ์ฉ๋๋ค. ๋ง์ง๋ง์ผ๋ก is_buy_flag๋ก ๋ฐ์ดํฐ๋ฅผ ๊ทธ๋ฃนํํ๊ณ ๊ฐ ๊ทธ๋ฃน์ ๊ด์ฐฐ ์๋ฅผ ๊ณ์ฐํ์ฌ ๊ฒฐ๊ณผ์ ๋ค์ด์ํ๋ง์ ๊ฒ์ฆํ๋ค.
R-092: ๊ณ ๊ฐ ๋ฐ์ดํฐ(df_customer)์ ์ฑ๋ณ์ ์ 3์ ๊ทํ์ผ๋ก ์ ๊ทํํ๋ผ.
df_gender_std = unique(df_customer[c("gender_cd", "gender")]) df_customer_std = df_customer[, colnames(df_customer) != "gender"]
## ๋ฐ์ดํฐ ๋ด์ฉ ํ์ธhead(df_customer_std, n = 3)
ย | customer_id | customer_name | gender_cd | birth_day | age | postal_cd | address | application_store_cd | application_date | status_cd |
---|---|---|---|---|---|---|---|---|---|---|
ย | <chr> | <chr> | <chr> | <date> | <int> | <chr> | <chr> | <chr> | <chr> | <chr> |
1 | CS021313000114 | ๅคง้ ใใๅญ | 1 | 1981-04-29 | 37 | 259-1113 | ็ฅๅฅๅท็ไผๅขๅๅธ็ฒ็ชช********** | S14021 | 20150905 | 0-00000000-0 |
2 | CS037613000071 | ๅ ญ่ง ้ ๅฝฆ | 9 | 1952-04-01 | 66 | 136-0076 | ๆฑไบฌ้ฝๆฑๆฑๅบๅ็ ********** | S13037 | 20150414 | 0-00000000-0 |
3 | CS031415000172 | ๅฎๅค็ฐ ่ฒด็พๅญ | 1 | 1976-10-04 | 42 | 151-0053 | ๆฑไบฌ้ฝๆธ่ฐทๅบไปฃใ ๆจ********** | S13031 | 20150529 | D-20100325-C |
# ๋ฐ์ดํฐ ๋ด์ฉ ํ์ธ head(df_gender_std, n = 3)
ย | gender_cd | gender |
---|---|---|
ย | <chr> | <chr> |
1 | 1 | ๅฅณๆง |
2 | 9 | ไธๆ |
6 | 0 | ็ทๆง |
์ค๋ช :
์ ์ฝ๋๋ ๊ณ ๊ฐ ์ ๋ณด๋ฅผ ์ ์ฅํ 'df_customer'๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ ์กฐ์ํ๊ณ ์์ต๋๋ค. ๋ค์์ ๊ฐ ์ฝ๋ ๋ผ์ธ์ ์ฒ๋ฆฌ ๋ด์ฉ์ ์๊ฐํฉ๋๋ค.
df_gender_std = unique(df_customer[c("gender_cd", "gender")]) - ์ด ์ฝ๋์์๋ df_gender_std๋ผ๋ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํฉ๋๋ค. df_customer ๋ฐ์ดํฐ ํ๋ ์์์ ๋ ๊ฐ์ ์ด, ํนํ "gender_cd"์ "gender"๋ผ๋ ์ด๋ฆ์ ์ด์ ์ ํํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ unique() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ค๋ณต๋ ํ์ ์ ๊ฑฐํ์ฌ ์๋ ๋ฐ์ดํฐ ํ๋ ์์ ํฌํจ๋ ์ฑ๋ณ ์ฝ๋์ ์ฑ๋ณ ๊ฐ์ ๊ณ ์ ํ ์กฐํฉ์ ๋ชจ๋ ํฌํจํ๋ ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํฉ๋๋ค.
df_customer_std = df_customer[, colnames(df_customer) ! = "gender"] - ์ด ์ฝ๋ ๋ผ์ธ์ df_customer_std๋ผ๋ ๋ ๋ค๋ฅธ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ ์์ฑํ๋ค. df_customer ๋ฐ์ดํฐ ํ๋ ์์์ "gender" ์ด์ ์ ์ธํ ๋ชจ๋ ์ด์ ๋ณต์ฌํฉ๋๋ค. ์ด๋ colnames() ํจ์์ ๋ ผ๋ฆฌ ์ฐ์ฐ์! =๋ฅผ ์ฌ์ฉํ์ฌ ์ด๋ฆ์ด "gender"์ ๊ฐ์ง ์์ ๋ชจ๋ ์ด์ ์ ํํ๋ฉด ๋ฉ๋๋ค. ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ ์๋์ df_customer ๋ฐ์ดํฐ ํ๋ ์๊ณผ ๋์ผํ ํ์ ๊ฐ์ง๋ง "gender" ์ด์ด ์์ต๋๋ค.
์ด ๋ ์ค์ ์ฝ๋๋ก ์ธํด ์๋์ df_customer ๋ฐ์ดํฐ ํ๋ ์์ ๊ณ ์ ํ ์ฑ๋ณ ์ฝ๋์ ๊ฐ๋ง ํฌํจํ๋ ๋ถ๋ถ๊ณผ ์ฑ๋ณ ์ด์ ์ ์ธํ ๋ค๋ฅธ ๋ชจ๋ ๊ณ ๊ฐ ์ ๋ณด๋ฅผ ํฌํจํ๋ ๋ถ๋ถ์ผ๋ก ๋๋๊ฒ ๋์์ต๋๋ค.
R-093: ์ํ ๋ฐ์ดํฐ(df_product)๋ ๊ฐ ์นดํ ๊ณ ๋ฆฌ์ ์ฝ๋ ๊ฐ๋ง ๋ณด์ ํ๊ณ ์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๋ณด์ ํ์ง ์๋๋ค. ์นดํ ๊ณ ๋ฆฌ ๋ฐ์ดํฐ(df_category)์ ๊ฒฐํฉํ์ฌ ๋น์ ๊ทํํ์ฌ ์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๋ณด์ ํ ์๋ก์ด ์ํ ๋ฐ์ดํฐ๋ฅผ ์์ฑํ๋ค.
df_product_full <- inner_join(df_product, df_category[c("category_small_cd", "category_major_name", "category_medium_name", "category_small_name")], by = "category_small_cd")
# ๋ฐ์ดํฐ ๋ด์ฉ ํ์ธ
head(df_product_full, n = 3)
ย | product_cd | category_major_cd | category_medium_cd | category_small_cd | unit_price | unit_cost | category_major_name | category_medium_name | category_small_name |
---|---|---|---|---|---|---|---|---|---|
ย | <chr> | <chr> | <chr> | <chr> | <int> | <int> | <chr> | <chr> | <chr> |
1 | P040101001 | 04 | 0401 | 040101 | 198 | 149 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
2 | P040101002 | 04 | 0401 | 040101 | 218 | 164 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
3 | P040101003 | 04 | 0401 | 040101 | 230 | 173 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
์ค๋ช :
์ ์ฝ๋๋ 'df_product'์ 'df_category'๋ผ๋ ๋ ๊ฐ์ ๋ฐ์ดํฐ ํ๋ ์์ ์กฐ์ํ๊ณ ์๋ค. ๋ค์์ ๊ฐ ์ฝ๋ ๋ผ์ธ์ ์ฒ๋ฆฌ ๋ด์ฉ์ ์๊ฐํฉ๋๋ค.
df_product_full <- inner_join(df_product, df_category[c("category_small_cd", "category_major_name", "category_medium_name", "category_ small_name")], by = "category_small_cd") - ์ด ์ฝ๋์์๋ df_product_full์ด๋ผ๋ ์๋ก์ด ๋ฐ์ดํฐ ํ๋ ์์ ๋ง๋ค๊ณ ์๋ค. ์ด๋ inner_join() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ "category_small_cd"๋ผ๋ ๊ณตํต ์ด์ ๊ธฐ์ค์ผ๋ก df_product์ df_category ๋ฐ์ดํฐ ํ๋ ์์ ๊ฒฐํฉํ๊ณ ์๋ค. ๊ทธ ๊ฒฐ๊ณผ "category_small_cd"์ ๊ฐ์ด ์ผ์นํ๋ ๋ ๋ฐ์ดํฐ ํ๋ ์์ ๋ชจ๋ ์ปฌ๋ผ์ ํฌํจํ๋ ๋ฐ์ดํฐ ํ๋ ์์ด ์์ฑ๋๋ฉฐ, df_category ๋ฐ์ดํฐ ํ๋ ์์ "category_small_cd", "category_major_name", "category_major_name", "category_medium_name", "category_medium_name", "category_medium_name". "category_medium_name", "category_small_name" ์ด๋ง ํฌํจํ๋๋ก ์๋ธ์ ํ๋์ด ์๋ค.
head(df_product_full, n = 3) - ์ด ์ฝ๋ ํ์ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ ๋ด์ฉ์ ํ์ธํ๋ ๋ฐ ์ฌ์ฉ๋๋ฉฐ, head() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๋ฐ์ดํฐ ํ๋ ์์ ์ฒ์ ์ธ ์ค์ ํ์ํ๋ค. ์ด๋ ๊ฒฐํฉ ์์ ์ด ์ฑ๊ณต์ ์ผ๋ก ์ํ๋์๋์ง ํ์ธํ๊ณ ์ถ๋ ฅ ํ์์ ํ์ธํ๊ธฐ ์ํด ๊ฒฐ๊ณผ ๋ฐ์ดํฐ ํ๋ ์์ ๋น ๋ฅด๊ฒ ๊ฒ์ฌํ๋ ๋ฐ ์ ์ฉํ ๋ฐฉ๋ฒ์ด๋ค.
R-094 : 093์์ ์์ฑ๋ ์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๊ฐ์ง ์ ํ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ์ฌ์์ผ๋ก ํ์ผ๋ก ์ ๋ฆฌํ๋ผ.
|ํ์ผ ํ์|ํค๋ ํฌํจ/๋ฏธํฌํจ|๋ฌธ์ ์ธ์ฝ๋ฉ||:โ:|:โ:|:โ:||CSV(์ผํ๋ก ๊ตฌ๋ถ๋ ๊ฐ)|์์|UTF-8|ยํ์ผ ์ถ๋ ฅ ๋์์ ๊ฒฝ๋ก๋ ๋ค์๊ณผ ๊ฐ์์ผ ํฉ๋๋ค.ย|์ถ๋ ฅ ๋์||:โ:||. /data|
# ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ write.csv(df_product_full, "../data/R_df_product_full_UTF-8_header.csv", row.names=FALSE, fileEncoding = "UTF-8")
ํด์ค:
์ ์ฝ๋๋ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ UTF-8 ์ธ์ฝ๋ฉ์ผ๋ก CSV ํ์ผ๋ก ์์ฑํ๊ณ ์์ผ๋ฉฐ, write.csv() ํจ์์ ๊ฐ ์ธ์์ ์ญํ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
df_product_full - CSV ํ์ผ๋ก ์ถ๋ ฅํ ๋ฐ์ดํฐ ํ๋ ์์ ๋๋ค.
"... /data/R_df_product_full_UTF-8_header.csv" - ์ถ๋ ฅ CSV ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ด๋ค. ๊ฒฝ๋ก์ ๋งจ ์์ ์๋ . ๋ ํ์ผ์ด ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ์์ ๋๋ ํ ๋ฆฌ์ ์ ์ฅ๋จ์ ์๋ฏธํ๋ฉฐ, R_df_product_full_UTF-8_header.csv๋ ์ถ๋ ฅ ํ์ผ์ ์ด๋ฆ์ด๋ค.
row.names=FALSE - ์ด ์ธ์๋ ์ถ๋ ฅ CSV ํ์ผ์ ํ ์ด๋ฆ์ ํฌํจํ์ง ์๋๋ก ์ง์ ํ๋ค.
fileEncoding = "UTF-8" - ์ถ๋ ฅ CSV ํ์ผ์ ์ธ์ฝ๋ฉ์ ์ง์ ํฉ๋๋ค. UTF-8์ ๋ค์ํ ์ธ์ด์ ๋ฌธ์๋ฅผ ๊ด๋ฒ์ํ๊ฒ ์ง์ํ๋ ๋ฌธ์ ์ธ์ฝ๋ฉ์ด๋ฏ๋ก ์์ด ์ด์ธ์ ๋ฌธ์๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐ ์ ํฉํฉ๋๋ค.
์์ฝํ๋ฉด write.csv() ํจ์๋ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ UTF-8 ์ธ์ฝ๋ฉ์ผ๋ก CSV ํ์ผ์ ์ฐ๊ณ ์ง์ ํ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ผ๋ก ์ ์ฅํฉ๋๋ค. ์์ฑ๋ CSV ํ์ผ์๋ ํ ์ด๋ฆ์ด ํฌํจ๋์ง ์์ต๋๋ค.
R-095: 093์์ ์์ฑ๋ ์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๊ฐ์ง ์ ํ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ์ฌ์์ผ๋ก ํ์ผ๋ก ์ ๋ฆฌํฉ๋๋ค.
|ํ์ผ ํ์|ํค๋ ํฌํจ/๋ฏธํฌํจ|๋ฌธ์ ์ธ์ฝ๋ฉ||:โ:|:โ:|:โ:||CSV(์ผํ๋ก ๊ตฌ๋ถ๋ ๊ฐ)|์์|CP932|ยํ์ผ ์ถ๋ ฅ ๋์์ ๊ฒฝ๋ก๋ ๋ค์๊ณผ ๊ฐ์์ผ ํฉ๋๋ค.ย|์ถ๋ ฅ ๋์||:โ:||. /data|
# ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ write.csv(df_product_full, "../data/R_df_product_full_CP932_header.csv", row.names = FALSE, fileEncoding = "CP932")
ํด์ค:
์ ์ฝ๋๋ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ CP932 ์ธ์ฝ๋ฉ์ผ๋ก CSV ํ์ผ๋ก ์์ฑํ๊ณ ์์ผ๋ฉฐ, write.csv() ํจ์์ ๊ฐ ์ธ์๊ฐ ์ํํ๋ ์์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
df_product_full - CSV ํ์ผ๋ก ์ถ๋ ฅํ ๋ฐ์ดํฐ ํ๋ ์์ ๋๋ค.
"... /data/R_df_product_full_CP932_header.csv" - ์ถ๋ ฅ CSV ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ ๋๋ค. ๊ฒฝ๋ก์ ๋งจ ์์ ์๋ . ์ ํ์ผ์ด ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ์์ ๋๋ ํ ๋ฆฌ์ ์ ์ฅ๋จ์ ์๋ฏธํ๋ฉฐ, R_df_product_full_CP932_header.csv๋ ์ถ๋ ฅ ํ์ผ์ ์ด๋ฆ์ด๋ค.
row.names=FALSE - ์ด ์ธ์๋ ์ถ๋ ฅ CSV ํ์ผ์ ํ ์ด๋ฆ์ ํฌํจํ์ง ์๋๋ก ์ง์ ํ๋ค.
fileEncoding = "CP932" - ์ถ๋ ฅ CSV ํ์ผ์ ์ธ์ฝ๋ฉ์ ์ง์ ํฉ๋๋ค. CP932๋ ์ผ๋ณธ์ด ํ ์คํธ์ ์ฌ์ฉ๋๋ ๋ฌธ์ ์ธ์ฝ๋ฉ์ผ๋ก ์ผ๋ณธ์ด์์ ์ฌ์ฉ๋๋ ๋ค์ํ ๋ฌธ์๋ฅผ ์ง์ํฉ๋๋ค.
์์ฝํ๋ฉด write.csv() ํจ์๋ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ CP932 ์ธ์ฝ๋ฉ์ผ๋ก CSV ํ์ผ์ ์ฐ๊ณ ์ง์ ๋ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ผ๋ก ์ ์ฅํ๋ค. ์์ฑ๋ CSV ํ์ผ์๋ ํ ์ด๋ฆ์ด ํฌํจ๋์ง ์๋๋ค. ์ด ์ธ์ฝ๋ฉ์ ์ผ๋ณธ์ด ํ ์คํธ ๋ฐ์ดํฐ๋ฅผ ๋ค๋ฃฐ ๋ ์ ์ฉํ๋ค.
ย
R-096: 093์์ ์์ฑ๋ ์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๊ฐ์ง ์ ํ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ์ฌ์์ผ๋ก ํ์ผ๋ก ์ ๋ฆฌํ๋ผ.
|ํ์ผ ํ์|ํค๋ ํฌํจ/๋ฏธํฌํจ|๋ฌธ์ ์ธ์ฝ๋ฉ||:โ:|:โ:|:โ:||CSV(์ผํ๋ก ๊ตฌ๋ถ๋ ๊ฐ)|์์|UTF-8|ยํ์ผ ์ถ๋ ฅ ๋์์ ๊ฒฝ๋ก๋ ๋ค์๊ณผ ๊ฐ์์ผ ํฉ๋๋ค.ย|์ถ๋ ฅ ๋์||:โ:||. /data|
# ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ write.table(df_product_full, "../data/R_df_product_full_UTF-8_noh.csv", row.names = FALSE, col.names = FALSE, sep = ",", fileEncoding = "UTF-8")
์ค๋ช :
์ ์ฝ๋๋ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ UTF-8 ์ธ์ฝ๋ฉ์ผ๋ก ํ ์คํธ ํ์ผ๋ก ์์ฑํ๊ณ ์์ผ๋ฉฐ, write.table() ํจ์์ ๊ฐ ์ธ์๊ฐ ์ํํ๋ ์์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
df_product_full - ํ ์คํธ ํ์ผ์ ์ธ ๋ฐ์ดํฐ ํ๋ ์์ ๋๋ค.
"... /data/R_df_product_full_UTF-8_noh.csv" - ์ถ๋ ฅ ํ ์คํธ ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ด๋ค. ๊ฒฝ๋ก์ ๋งจ ์์ ์๋ . ๋ ํ์ผ์ด ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ์์ ๋๋ ํ ๋ฆฌ์ ์ ์ฅ๋จ์ ์๋ฏธํ๋ฉฐ, R_df_product_full_UTF-8_no.csv๋ ์ถ๋ ฅ ํ์ผ์ ์ด๋ฆ์ด๋ค.
row.names = FALSE - ์ด ์ธ์๋ ์ถ๋ ฅ ํ ์คํธ ํ์ผ์ ํ ์ด๋ฆ์ ํฌํจํ์ง ์๋๋ก ์ง์ ํ๋ค.
col.names = FALSE - ์ด ์ธ์๋ ์ถ๋ ฅ ํ ์คํธ ํ์ผ์ ์ด ์ด๋ฆ์ ํฌํจํ์ง ์๋๋ก ์ง์ ํ๋ค.
sep = "," - ์ด ์ธ์๋ ์ถ๋ ฅ ํ ์คํธ ํ์ผ์ ์ด ์ฌ์ด์ ์ฌ์ฉํ ๊ตฌ๋ถ์๋ฅผ ์ง์ ํ๋ค. ์ด ๊ฒฝ์ฐ ์ผํ๊ฐ ๊ตฌ๋ถ ๊ธฐํธ๋ก ์ฌ์ฉ๋๋ค.
fileEncoding = "UTF-8" - ์ด ์ธ์๋ ์ถ๋ ฅ ํ ์คํธ ํ์ผ์ ์ธ์ฝ๋ฉ์ ์ง์ ํ๋๋ฐ, UTF-8์ ๋ค์ํ ์ธ์ด์ ๋ฌธ์๋ฅผ ๊ด๋ฒ์ํ๊ฒ ์ง์ํ๋ ๋ฌธ์ ์ธ์ฝ๋ฉ์ด๋ฏ๋ก ์์ด ์ด์ธ์ ๋ฌธ์๋ฅผ ์ฒ๋ฆฌํ๋ ๋ฐ ์ ํฉํ๋ค.
์์ฝํ๋ฉด write.table() ํจ์๋ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ UTF-8 ์ธ์ฝ๋ฉ์ผ๋ก ํ ์คํธ ํ์ผ์ ์ฐ๊ณ ์ง์ ํ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ ์ ์ฅํ๋ค. ์์ฑ๋ ํ ์คํธ ํ์ผ์ ํ๋ช ์ด๋ ์ด๋ช ์ ํฌํจํ์ง ์๊ณ ์ผํ๋ฅผ ๊ตฌ๋ถ ๊ธฐํธ๋ก ์ฌ์ฉํฉ๋๋ค.
ย
R-097:ย 094์์ ๋ง๋ ๋ค์ ํ์์ ํ์ผ์ ๋ก๋ํ๊ณ ์ธ ๊ฐ์ ๋ฐ์ดํฐ ํญ๋ชฉ์ ํ์ํ ๋ค์ ์ฌ๋ฐ๋ฅด๊ฒ ๊ฐ์ ธ์๋์ง ํ์ธํฉ๋๋ค.
|ํ์ผ ํ์|ํค๋ ํฌํจ/๋ฏธํฌํจ|๋ฌธ์ ์ธ์ฝ๋ฉ||:โ:|:โ:|:โ:||CSV(์ผํ๋ก ๊ตฌ๋ถ๋ ๊ฐ)|์์|UTF-8|
# ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ c_class <- c(NA, "character", "character", "character", NA, NA, NA, NA, NA) df_product_full <- read.csv("../data/R_df_product_full_UTF-8_header.csv", colClasses = c_class, fileEncoding = "UTF-8") head(df_product_full, 3)
ย | product_cd | category_major_cd | category_medium_cd | category_small_cd | unit_price | unit_cost | category_major_name | category_medium_name | category_small_name |
---|---|---|---|---|---|---|---|---|---|
ย | <chr> | <chr> | <chr> | <chr> | <int> | <int> | <chr> | <chr> | <chr> |
1 | P040101001 | 04 | 0401 | 040101 | 198 | 149 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
2 | P040101002 | 04 | 0401 | 040101 | 218 | 164 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
3 | P040101003 | 04 | 0401 | 040101 | 230 | 173 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
์ค๋ช :
์์ ์ฝ๋๋ R_df_product_full_UTF-8_header.csv๋ผ๋ CSV ํ์ผ์ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ ์ฝ์ด๋ค์ด๊ณ ์์ผ๋ฉฐ, read.csv() ํจ์์ ๊ฐ ์ธ์๊ฐ ์ํํ๋ ์์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
"... /data/R_df_product_full_UTF-8_header.csv" - ์ ๋ ฅ CSV ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ด๋ค. ๊ฒฝ๋ก ์์ . ๋ ํ์ผ์ด ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ์์ ๋๋ ํ ๋ฆฌ์ ์์์ ์๋ฏธํ๋ค.
colClasses = c_class - ์ด ์ธ์๋ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์ ํด๋์ค๋ฅผ ์ง์ ํ๋ ๋ฒกํฐ์ด๋ค. ์ด ๊ฒฝ์ฐ 1์ด๊ณผ 5~9์ด์ NA๋ก ์ค์ ๋์ด ํด๋์ค๊ฐ ์๋์ผ๋ก ๊ฒฐ์ ๋จ์ ๋ํ๋ด๋ฉฐ, 2์ด๋ถํฐ 4์ด๊น์ง๋ character๋ก ์ค์ ๋์ด ๋ฌธ์์ด๋ก ์ฒ๋ฆฌ๋จ์ ๋ํ๋ธ๋ค.
fileEncoding = "UTF-8" - ์ด ์ธ์๋ ์ ๋ ฅ CSV ํ์ผ์ ์ธ์ฝ๋ฉ์ ์ง์ ํ๋๋ฐ, UTF-8์ ๋ค์ํ ์ธ์ด์ ๋ฌธ์๋ฅผ ํญ๋๊ฒ ์ง์ํ๋ ๋ฌธ์ ์ธ์ฝ๋ฉ์ด๋ค.
head(df_product_full, 3) - ์ด ๋ช ๋ น์ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ ์ฒ์ ์ธ ์ค์ ์ฝ์์ ํ์ํ๋ค.
์์ฝํ๋ฉด, read.csv() ํจ์๋ R_df_product_full_UTF-8_header.csv ํ์ผ์ ์ง์ ํ ์ด ํด๋์ค์ ํ์ผ ์ธ์ฝ๋ฉ์ ์ฌ์ฉํ์ฌ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ผ๋ก ์ฝ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์์ฑ๋ ๋ฐ์ดํฐ ํ๋ ์์ head() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ฝ์์ ์ถ๋ ฅํ๋ค.
R-098: 096์์ ๋ง๋ ๋ค์ ํ์์ ํ์ผ์ ๋ก๋ํ๊ณ ์ธ ๊ฐ์ ๋ฐ์ดํฐ ํญ๋ชฉ์ ํ์ํ ๋ค์ ์ฌ๋ฐ๋ฅด๊ฒ ๊ฐ์ ธ์๋์ง ํ์ธํฉ๋๋ค.
|ํ์ผ ํ์|ํค๋ ํฌํจ/๋ฏธํฌํจ|๋ฌธ์ ์ธ์ฝ๋ฉ||:โ:|:โ:|:โ:||CSV(์ผํ๋ก ๊ตฌ๋ถ๋ ๊ฐ)|์์|UTF-8|
# ์ฝ๋ ์์ 1 (๋์ค์ ํญ๋ชฉ ์ด๋ฆ ๋ถ์ด๊ธฐ) # ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ
c_class <- c(NA, "character", "character", "character", NA, NA, NA, NA, NA)
df_product_full <- read.csv("../data/R_df_product_full_UTF-8_noh.csv", colClasses = c_class, header = FALSE, fileEncoding = "UTF-8")
colnames(df_product_full) <- c("product_cd", "category_major_cd", "category_medium_cd", "category_small_cd", "unit_price", "unit_cost", "category_major_name", "category_medium_name", "category_small_name")
head(df_product_full, 3)
ย | product_cd | category_major_cd | category_medium_cd | category_small_cd | unit_price | unit_cost | category_major_name | category_medium_name | category_small_name |
---|---|---|---|---|---|---|---|---|---|
ย | <chr> | <chr> | <chr> | <chr> | <int> | <int> | <chr> | <chr> | <chr> |
1 | P040101001 | 04 | 0401 | 040101 | 198 | 149 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
2 | P040101002 | 04 | 0401 | 040101 | 218 | 164 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
3 | P040101003 | 04 | 0401 | 040101 | 230 | 173 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
์ค๋ช :
์ ์ฝ๋๋ R_df_product_full_UTF-8_no.csv๋ผ๋ CSV ํ์ผ์ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ ์ฝ์ด๋ค์ฌ ์๋ก์ด ์ด ์ด๋ฆ์ ๋ฐ์ดํฐ ํ๋ ์์ ํ ๋นํ๊ณ ์์ผ๋ฉฐ, read.csv() ํจ์์ ๊ฐ ์ธ์๊ฐ ํ๋ ์ผ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ๊ณผ ๊ฐ์ต๋๋ค.
"... /data/R_df_product_full_UTF-8_noh.csv" - ์ ๋ ฅ CSV ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ด๋ค. ๊ฒฝ๋ก ์์ . ๋ ํ์ผ์ด ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ์์ ๋๋ ํ ๋ฆฌ์ ์์์ ์๋ฏธํ๋ค.
colClasses = c_class - ์ด ์ธ์๋ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์ ํด๋์ค๋ฅผ ์ง์ ํ๋ ๋ฒกํฐ์ด๋ค. ์ด ๊ฒฝ์ฐ 1์ด๊ณผ 5~9์ด์ NA๋ก ์ค์ ๋์ด ํด๋์ค๊ฐ ์๋์ผ๋ก ๊ฒฐ์ ๋จ์ ๋ํ๋ด๋ฉฐ, 2~4์ด์ character๋ก ์ค์ ๋์ด ๋ฌธ์์ด๋ก ์ฒ๋ฆฌํด์ผ ํจ์ ๋ํ๋ธ๋ค.
header = FALSE - ์ด ์ธ์๋ ์ ๋ ฅ CSV ํ์ผ์ ํค๋ ํ์ด ์์์ ์ง์ ํ๋ค.
fileEncoding = "UTF-8" - ์ด ์ธ์๋ ์ ๋ ฅ CSV ํ์ผ์ ์ธ์ฝ๋ฉ์ ์ง์ ํ๋๋ฐ, UTF-8์ ๋ค์ํ ์ธ์ด์ ๋ฌธ์๋ฅผ ํญ๋๊ฒ ์ง์ํ๋ ๋ฌธ์ ์ธ์ฝ๋ฉ์ด๋ค.
colnames(df_product_full) <- c("product_cd", "category_major_cd", "category_medium_cd", "category_small_cd", "unit_price", "unit_cost", " category_major_name", "category_medium_name", "category_small_name") - ๋ฐ์ดํฐ ํ๋ ์์ ์๋ก์ด ์ปฌ๋ผ ์ด๋ฆ์ ๋ถ์ฌํ๋ ๋ช ๋ น์ด์ด๋ค. ์๋ก์ด ์ปฌ๋ผ ์ด๋ฆ์ "product_cd", "category_major_cd", "category_medium_cd", "category_small_cd", "unit_price", "unit_cost", "category_major_name", " category_medium_name", "category_small_name", "category_small_name"์ ์์๋ก ์ ๋ ฅํ๋ค.
head(df_product_full, 3) - ์ด ๋ช ๋ น์ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ ์ฒ์ ์ธ ์ค์ ์ฝ์์ ํ์ํ๋ค.
์์ฝํ๋ฉด, read.csv() ํจ์๋ R_df_product_full_UTF-8_noh.csv ํ์ผ์ ์ง์ ๋ ์ด ํด๋์ค, ํค๋ ์ค์ , ํ์ผ ์ธ์ฝ๋ฉ์ ์ฌ์ฉํ์ฌ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ผ๋ก ์ฝ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์์ฑ๋ ๋ฐ์ดํฐ ํ๋ ์์ ์๋ก์ด ์ปฌ๋ผ ์ด๋ฆ์ ๋ถ์ฌํ๊ณ head() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ฝ์์ ์ถ๋ ฅํ๋ค.
# ์ฝ๋ ์์ 2(ํญ๋ชฉ ์ด๋ฆ์ ๋จผ์ ์ ์) # ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ
c_names <- c("product_cd", "category_major_cd", "category_medium_cd", "category_small_cd", "unit_price","unit_cost", "category_major_name", "category_medium_name", "category_small_name") c_class <- c(NA, "character", "character", "character", NA, NA, NA, NA, NA)
df_product_full <- read.csv("../data/R_df_product_full_UTF-8_noh.csv", col.names = c_names, colClasses = c_class, header = FALSE, fileEncoding = "UTF-8")
head(df_product_full, 3)
ย | product_cd | category_major_cd | category_medium_cd | category_small_cd | unit_price | unit_cost | category_major_name | category_medium_name | category_small_name |
---|---|---|---|---|---|---|---|---|---|
ย | <chr> | <chr> | <chr> | <chr> | <int> | <int> | <chr> | <chr> | <chr> |
1 | P040101001 | 04 | 0401 | 040101 | 198 | 149 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
2 | P040101002 | 04 | 0401 | 040101 | 218 | 164 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
3 | P040101003 | 04 | 0401 | 040101 | 230 | 173 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
์ค๋ช :
์ ์ฝ๋๋ R_df_product_full_UTF-8_no.csv๋ผ๋ CSV ํ์ผ์ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ ์ฝ์ด๋ค์ฌ ์๋ก์ด ์ด ์ด๋ฆ์ ๋ฐ์ดํฐ ํ๋ ์์ ํ ๋นํ๊ณ ์์ผ๋ฉฐ, read.csv() ํจ์์ ๊ฐ ์ธ์๊ฐ ํ๋ ์ผ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ๊ณผ ๊ฐ์ต๋๋ค.
"... /data/R_df_product_full_UTF-8_noh.csv" - ์ ๋ ฅ CSV ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ด๋ค. ๊ฒฝ๋ก ์์ . ๋ ํ์ผ์ด ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ์์ ๋๋ ํ ๋ฆฌ์ ์์์ ์๋ฏธํ๋ค.
col.names = c_names - ์ด ์ธ์๋ ๋ฐ์ดํฐ ํ๋ ์์์ ์ฌ์ฉํ ์ด ์ด๋ฆ์ ์ง์ ํ๋ค. c_names๋ ์ ๋ ฅ ํ์ผ์ ๋ํ๋๋ ๊ฒ๊ณผ ๋์ผํ ์์๋ก ์ ์ด ์ด๋ฆ์ ๋์ดํ๋ ๋ฌธ์ ๋ฒกํฐ์ด๋ค.
colClasses = c_class - ์ด ์ธ์๋ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์ ํด๋์ค๋ฅผ ์ง์ ํ๋ค. c_class๋ ๋ฐ์ดํฐ ํ๋ ์์ ๊ฐ ์ด์ ํด๋์ค๋ฅผ ์ง์ ํ๋ ๋ฒกํฐ์ด๋ค. ์ด ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์ด์ NA๋ก ์ค์ ๋์ด ํด๋น ํด๋์ค๊ฐ ์๋์ผ๋ก ๊ฒฐ์ ๋จ์ ๋ํ๋ด๋ฉฐ, ๋ ๋ฒ์งธ๋ถํฐ ๋ค ๋ฒ์งธ ์ด์ character๋ก ์ค์ ๋์ด ๋ฌธ์์ด๋ก ์ฒ๋ฆฌ๋จ์ ๋ํ๋ด๋ฉฐ, ๋ค์ฏ ๋ฒ์งธ์ ์ฌ์ฏ ๋ฒ์งธ ์ด์ NA๋ก ์ค์ ๋์ด ํด๋น ํด๋์ค๊ฐ ์๋์ผ๋ก ๊ฒฐ์ ๋์ด์ผ ํจ์ ๋ํ๋ธ๋ค. ๋ง์ง๋ง 3์ด์ NA๋ก ์ค์ ๋์ด ๊ฒฐ์๊ฐ์ผ๋ก ์ฒ๋ฆฌํด์ผ ํจ์ ๋ํ๋ธ๋ค.
header = FALSE - ์ด ์ธ์๋ ์ ๋ ฅ CSV ํ์ผ์ ํค๋ ํ์ด ์์์ ์ง์ ํ๋ค.
fileEncoding = "UTF-8" - ์ด ์ธ์๋ ์ ๋ ฅ CSV ํ์ผ์ ์ธ์ฝ๋ฉ์ ์ง์ ํ๋๋ฐ, UTF-8์ ๋ค์ํ ์ธ์ด์ ๋ฌธ์๋ฅผ ๊ด๋ฒ์ํ๊ฒ ์ง์ํ๋ ๋ฌธ์ ์ธ์ฝ๋ฉ์ด๋ค.
head(df_product_full, 3) - ์ด ๋ช ๋ น์ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ ์ฒ์ ์ธ ์ค์ ์ฝ์์ ํ์ํ๋ค.
์์ฝํ๋ฉด, read.csv() ํจ์๋ R_df_product_full_UTF-8_no.csv ํ์ผ์ ์ง์ ํ ์ด ์ด๋ฆ, ์ด ํด๋์ค, ํค๋ ์ค์ , ํ์ผ ์ธ์ฝ๋ฉ์ ์ฌ์ฉํ์ฌ df_product_full์ด๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ผ๋ก ์ฝ๋๋ค. ๊ทธ๋ฆฌ๊ณ ์์ฑ๋ ๋ฐ์ดํฐ ํ๋ ์์ head() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ์ฝ์๋ก ์ถ๋ ฅํ๋ค.
R-099: 093์์ ์์ฑ๋ ์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๊ฐ์ง ์ ํ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ์ฌ์์ผ๋ก ํ์ผ๋ก ์ ๋ฆฌํฉ๋๋ค.
|ํ์ผ ํ์|ํค๋ ํฌํจ/๋ฏธํฌํจ|๋ฌธ์ ์ธ์ฝ๋ฉ||:โ:|:โ:|:โ:||TSV(ํญ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฐ)|์์|UTF-8|ยํ์ผ ์ถ๋ ฅ ๋์์ ๊ฒฝ๋ก๋ ๋ค์๊ณผ ๊ฐ์์ผ ํฉ๋๋ค.ย|์ถ๋ ฅ ๋์||:โ:||. /data|
# ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ write.table(df_product_full, "../data/R_df_product_full_UTF-8_header.tsv", row.names = FALSE, sep = "\t", fileEncoding = "UTF-8")
์ค๋ช :
์ ์ฝ๋๋ ๋ฐ์ดํฐ ํ๋ ์ df_product_full์ ๋ด์ฉ์ R_df_product_full_UTF-8_header.tsv๋ผ๋ ํญ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฐ(TSV) ํ์ผ๋ก ์์ฑํ๊ณ ์๋ค. ๋ค์์ write.table() ํจ์์ ๊ฐ ์ธ์๊ฐ ๋ฌด์์ ํ๋์ง ์ค๋ช ํฉ๋๋ค.
df_product_full - TSV ํ์ผ์ ์ธ ๋ฐ์ดํฐ ํ๋ ์์ ๋๋ค.
"... /data/R_df_product_full_UTF-8_header.tsv" - ์ถ๋ ฅ TSV ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ ๋๋ค. ๊ฒฝ๋ก์ ๋งจ ์์ ์๋ ... ๋ ํ์ผ์ด ํ์ฌ ์์ ๋๋ ํ ๋ฆฌ์ ์์ ๋๋ ํ ๋ฆฌ์ ์์นํ๋ค๋ ๊ฒ์ ์๋ฏธํ๋ค.
row.names = FALSE - ์ด ์ธ์๋ ์ถ๋ ฅ ํ์ผ์ ํ ์ด๋ฆ์ ํฌํจํ์ง ์๋๋ก ์ง์ ํ๋ค.
sep = "\t" - ์ด ์ธ์๋ ์ด ์ฌ์ด์ ์ฌ์ฉํ ๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ์ง์ ํ๋ค. ์ด ๊ฒฝ์ฐ ๊ตฌ๋ถ ๊ธฐํธ๋ ํญ ๋ฌธ์์ด๋ค.
fileEncoding = "UTF-8" - ์ด ์ธ์๋ ์ถ๋ ฅ TSV ํ์ผ์ ์ธ์ฝ๋ฉ์ ์ง์ ํฉ๋๋ค. UTF-8์ ๋ค์ํ ์ธ์ด์ ๋ค์ํ ๋ฌธ์๋ฅผ ์ง์ํ๋ ๋ฌธ์ ์ธ์ฝ๋ฉ์ ๋๋ค.
์์ฝํ๋ฉด, write.table() ํจ์๋ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ ๋ด์ฉ์ ํญ์ ๊ตฌ๋ถ ๊ธฐํธ๋ก, UTF-8์ ํ์ผ ์ธ์ฝ๋ฉ์ผ๋ก ์ฌ์ฉํ์ฌ R_df_product_full_UTF-8_header.tsv๋ผ๋ TSV ํ์ผ๋ก ์์ฑํ๊ณ ์์ต๋๋ค. ํฉ๋๋ค.
R-100: 093์์ ์์ฑ๋ ์นดํ ๊ณ ๋ฆฌ ์ด๋ฆ์ ๊ฐ์ง ์ ํ ๋ฐ์ดํฐ๋ฅผ ๋ค์ ์ฌ์์ ํ์ผ๋ก ์ ๋ฆฌํฉ๋๋ค.
|ํ์ผ ํ์|ํค๋ ํฌํจ/๋ฏธํฌํจ|๋ฌธ์ ์ธ์ฝ๋ฉ||:โ:|:โ:|:โ:||TSV(ํญ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฐ)|์์|UTF-8|
# ๋ต์ ํ์ผ์ ์์น๊ฐ ๋ฌธ์ ํ์ผ๊ณผ ๋ค๋ฅด๊ธฐ ๋๋ฌธ์ ๊ฒฝ๋ก๊ฐ '. /data'๋ก ๋์ด ์๋ ์ ์ฐธ๊ณ
c_class <- c(NA, "character", "character", "character", NA, NA, NA, NA, NA)
df_product_tmp <- read.table("../data/R_df_product_full_UTF-8_header.tsv", colClasses = c_class, header = TRUE, fileEncoding = "UTF-8")
head(df_product_tmp,3)
ย | product_cd | category_major_cd | category_medium_cd | category_small_cd | unit_price | unit_cost | category_major_name | category_medium_name | category_small_name |
---|---|---|---|---|---|---|---|---|---|
ย | <chr> | <chr> | <chr> | <chr> | <int> | <int> | <chr> | <chr> | <chr> |
1 | P040101001 | 04 | 0401 | 040101 | 198 | 149 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
2 | P040101002 | 04 | 0401 | 040101 | 218 | 164 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
3 | P040101003 | 04 | 0401 | 040101 | 230 | 173 | ๆฃ่ | ๅพก้ฃฏ้ก | ๅผๅฝ้ก |
์ค๋ช :
์ ์ฝ๋๋ R_df_product_full_UTF-8_header.tsv๋ผ๋ ํญ์ผ๋ก ๊ตฌ๋ถ๋ ๊ฐ(TSV) ํ์ผ์ ์ฝ๊ณ ๊ทธ ๋ด์ฉ์ df_product_tmp๋ผ๋ ๋ฐ์ดํฐ ํ๋ ์์ ์ ์ฅํ๋ ์ฝ๋์ด๋ฉฐ, read.table() ํจ์์ ๊ฐ ์ธ์์ ์ญํ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค. ๊ณผ ๊ฐ์ต๋๋ค.
c_class - TSV ํ์ผ ๋ด ๊ฐ ์ด์ ํด๋์ค๋ฅผ ์ง์ ํ๋ ๋ฒกํฐ์ ๋๋ค. ์ด ๊ฒฝ์ฐ ์ฒซ ๋ฒ์งธ ์ด์ NA๋ก, ๋ค๋ฅธ ์ด์ "character"๋ผ๋ ํด๋์ค๋ก ์ง์ ๋์ด ์์ต๋๋ค.
"... /data/R_df_product_full_UTF-8_header.tsv" - ์ ๋ ฅ TSV ํ์ผ์ ํ์ผ ๊ฒฝ๋ก์ ํ์ผ ์ด๋ฆ์ด๋ค.
colClasses = c_class - ์ ๋ ฅ TSV ํ์ผ์ ์ด ํด๋์ค๋ฅผ ์ง์ ํ๋ค.
header = TRUE - ์ด ์ธ์๋ ์ ๋ ฅ ํ์ผ์ ์ฒซ ๋ฒ์งธ ํ์ ์ด ์ด๋ฆ์ ํฌํจํ๋๋ก ์ง์ ํ๋ค.
fileEncoding = "UTF-8" - ์ ๋ ฅ TSV ํ์ผ์ ๋ฌธ์ ์ธ์ฝ๋ฉ์ ์ง์ ํ๋ค.
TSV ํ์ผ์ ์ฝ์ ํ head() ํจ์๋ฅผ ์ฌ์ฉํ์ฌ ๊ฒฐ๊ณผ df_product_tmp ๋ฐ์ดํฐ ํ๋ ์์ ์ฒ์ 3์ค์ ํ์ํ๋ค.
์ ์ฒด์ ์ผ๋ก ์ด ์ฝ๋๋ CSV ํ์ผ์ ์ฝ๊ณ ๊ทธ ๋ด์ฉ์ df_product_full ๋ฐ์ดํฐ ํ๋ ์์ ์ ์ฅํ๊ธฐ ์ ์ ์ฝ๋์ ์ ์ฌํ๋ค. ํ์ง๋ง ์ด ์ฝ๋์์๋ TSV ํ์ผ์ ์ฝ๊ณ ๊ทธ ๋ด์ฉ์ df_product_tmp๋ผ๋ ์์ ๋ฐ์ดํฐ ํ๋ ์์ ์ ์ฅํฉ๋๋ค. ์์ ๋ฐ์ดํฐ ํ๋ ์์ ์ฌ์ฉํ๋ ๋ชฉ์ ์ ์ต์ข ๊ฒฐ๊ณผ๋ฅผ ๋ค๋ฅธ ์ด๋ฆ์ ๋ฐ์ดํฐ ํ๋ ์์ ์ ์ฅํ๊ธฐ ์ ์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฆฌํ๊ฑฐ๋ ์กฐ์ํ๊ธฐ ์ํ ๊ฒ์ผ ์ ์๋ค.
ย
Comment