library(tidyr)
library(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
LaptopData <- read.csv("~/Downloads/laptopData.csv")
head(LaptopData)
##   Unnamed..0 Company  TypeName Inches                   ScreenResolution
## 1          0   Apple Ultrabook   13.3 IPS Panel Retina Display 2560x1600
## 2          1   Apple Ultrabook   13.3                           1440x900
## 3          2      HP  Notebook   15.6                  Full HD 1920x1080
## 4          3   Apple Ultrabook   15.4 IPS Panel Retina Display 2880x1800
## 5          4   Apple Ultrabook   13.3 IPS Panel Retina Display 2560x1600
## 6          5    Acer  Notebook   15.6                           1366x768
##                          Cpu  Ram              Memory
## 1       Intel Core i5 2.3GHz  8GB           128GB SSD
## 2       Intel Core i5 1.8GHz  8GB 128GB Flash Storage
## 3 Intel Core i5 7200U 2.5GHz  8GB           256GB SSD
## 4       Intel Core i7 2.7GHz 16GB           512GB SSD
## 5       Intel Core i5 3.1GHz  8GB           256GB SSD
## 6    AMD A9-Series 9420 3GHz  4GB           500GB HDD
##                            Gpu      OpSys Weight     Price
## 1 Intel Iris Plus Graphics 640      macOS 1.37kg  71378.68
## 2       Intel HD Graphics 6000      macOS 1.34kg  47895.52
## 3        Intel HD Graphics 620      No OS 1.86kg  30636.00
## 4           AMD Radeon Pro 455      macOS 1.83kg 135195.34
## 5 Intel Iris Plus Graphics 650      macOS 1.37kg  96095.81
## 6                AMD Radeon R5 Windows 10  2.1kg  21312.00
tidy_LaptopData <- LaptopData %>%
  mutate(Memory = ifelse(Memory == "?" | Memory == "N/A", NA, Memory)) %>%
  separate(Memory, into = c("Storage_Size", "Storage_Type"), sep = " ", extra = "merge", fill = "right") %>%
  mutate(Storage_Size = as.numeric(gsub("GB|TB", "", Storage_Size)),
         Storage_Type = ifelse(grepl("TB", Storage_Type), "TB", "GB"))
tidy_LaptopData <- tidy_LaptopData %>%
  mutate(Inches = as.numeric(Inches), 
         Ram = as.numeric(gsub("GB", "", Ram)), 
         Weight = as.numeric(gsub("kg", "", Weight)))
## Warning: There were 2 warnings in `mutate()`.
## The first warning was:
## ℹ In argument: `Inches = as.numeric(Inches)`.
## Caused by warning:
## ! NAs introduced by coercion
## ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
cleaned_LaptopData <- tidy_LaptopData %>%
  filter(!is.na(Inches), !is.na(Ram), !is.na(Weight))
laptop_summary <- cleaned_LaptopData %>%
  group_by(Company) %>%
  summarize(Average_Inches = mean(Inches, na.rm = TRUE),
            Average_Ram = mean(Ram, na.rm = TRUE),
            Average_Weight = mean(Weight, na.rm = TRUE))
head(laptop_summary)
## # A tibble: 6 × 4
##   Company Average_Inches Average_Ram Average_Weight
##   <chr>            <dbl>       <dbl>          <dbl>
## 1 Acer              15.1        5.85           2.27
## 2 Apple             13.2        9.33           1.32
## 3 Asus              15.6        9.60           2.31
## 4 Chuwi             14.5        4.67           1.73
## 5 Dell              15.2        9.35           2.17
## 6 Fujitsu           15.6        6              2.25