library("plyr")
library("dplyr")
library("tidyr")
library("readxl")
library("knitr")
Using R, clean the data set refine to make it easier to visualize and analyze.
refine_original <- read_excel("C:/Users/xena0/Downloads/refine.xlsx")
View(refine_original)
refine_clean <- refine_original %>%
mutate(company = ifelse(grepl("^phil|^fil|^phl", company, ignore.case = TRUE), "philips", company)) %>%
mutate(company = ifelse(grepl("ak", company, ignore.case = TRUE), "akzo", company)) %>%
mutate(company = ifelse(grepl("van", company, ignore.case = TRUE), "van houten", company)) %>%
mutate(company = ifelse(grepl("uni", company, ignore.case = TRUE), "unilever", company))
refine_clean <- refine_clean %>%
separate(col = "Product code / number",
into = c("product_code", "product_number"),
sep = "-")
refine_clean <- mutate(refine_clean, product_categories = 0)
refine_clean <- refine_clean %>%
mutate(product_categories = ifelse(grepl("p", product_code), "Smartphone", product_categories)) %>%
mutate(product_categories = ifelse(grepl("v", product_code), "TV", product_categories)) %>%
mutate(product_categories = ifelse(grepl("x", product_code), "Laptop", product_categories)) %>%
mutate(product_categories = ifelse(grepl("q", product_code), "Tablet", product_categories))
refine_clean <- refine_clean %>%
unite(full_address, address:country, sep = ", ", remove = FALSE)
refine_clean <- refine_clean %>%
mutate(company_philips = ifelse(grepl("philips", company), 1, 0)) %>%
mutate(company_akzo = ifelse(grepl("akzo", company), 1, 0)) %>%
mutate(company_van_houten = ifelse(grepl("van houten", company), 1, 0)) %>%
mutate(company_unilever = ifelse(grepl("unilever", company), 1, 0)) %>%
mutate(product_smartphone = ifelse(grepl("Smartphone", product_categories), 1, 0)) %>%
mutate(product_tv = ifelse(grepl("TV", product_categories), 1, 0)) %>%
mutate(product_laptop = ifelse(grepl("Laptop", product_categories), 1, 0)) %>%
mutate(product_tablet = ifelse(grepl("Tablet", product_categories), 1, 0))
kable(refine_clean[1:5, ], caption = "refine clean")
| company | product_code | product_number | full_address | address | city | country | name | product_categories | company_philips | company_akzo | company_van_houten | company_unilever | product_smartphone | product_tv | product_laptop | product_tablet |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| philips | p | 5 | Groningensingel 147, arnhem, the netherlands | Groningensingel 147 | arnhem | the netherlands | dhr p. jansen | Smartphone | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| philips | p | 43 | Groningensingel 148, arnhem, the netherlands | Groningensingel 148 | arnhem | the netherlands | dhr p. hansen | Smartphone | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
| philips | x | 3 | Groningensingel 149, arnhem, the netherlands | Groningensingel 149 | arnhem | the netherlands | dhr j. Gansen | Laptop | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| philips | x | 34 | Groningensingel 150, arnhem, the netherlands | Groningensingel 150 | arnhem | the netherlands | dhr p. mansen | Laptop | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |
| philips | x | 12 | Groningensingel 151, arnhem, the netherlands | Groningensingel 151 | arnhem | the netherlands | dhr p. fransen | Laptop | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 0 |