Pros
It is very easy to read and write, which helps in debugging and manual editing.
It has a flexible structure that supports nested data structures, arrays etc. (making it versatile for various types of data)
Cons
There is no official way to include comments, which can be a drawback for documentation and new code users.
For very large datasets, parsing JSON can be slower compared to some other formats.
Pros
It is very accessible since most web browsers can interpret HTML.
HTML is ideal for rendering data in a browser with formatting and styling since it was designed for web display
Cons
The additional tags and formatting can add unnecessary overhead when only data is needed.
Extracting structured data from HTML can require additional processing and parsing.
Pros
Well-suited for complex, nested, and hierarchical data.
Despite being verbose, XML’s clear tag structure makes it relatively easy to read and understand, which can be helpful during development and debugging.
Cons
Parsing XML can be slower and more memory-intensive than more compact formats
The verbose nature of the data structure leads to the creation of a very large XML file size. This large data size can be an issue for some applications
Pros
Since it is a columnar format, Parquet is ideal for analytical queries where only a subset of columns are read.
It has efficient storage since Parquet compresses data very effectively, reducing disk space and input/output.
Cons - Not human readable, you can’t easily inspect the file without specialized tools.
options(repos = c(CRAN = "https://cran.rstudio.com/"))
install.packages("XML")
##
## The downloaded binary packages are in
## /var/folders/nz/h7z329n55nxfs2dv7hmbhc400000gn/T//Rtmp0Ico4o/downloaded_packages
install.packages("arrow")
##
## The downloaded binary packages are in
## /var/folders/nz/h7z329n55nxfs2dv7hmbhc400000gn/T//Rtmp0Ico4o/downloaded_packages
install.packages("jsonlite")
##
## The downloaded binary packages are in
## /var/folders/nz/h7z329n55nxfs2dv7hmbhc400000gn/T//Rtmp0Ico4o/downloaded_packages
install.packages("readr")
##
## The downloaded binary packages are in
## /var/folders/nz/h7z329n55nxfs2dv7hmbhc400000gn/T//Rtmp0Ico4o/downloaded_packages
library(jsonlite) # For JSON conversion
library(knitr) # For HTML table generation
library(XML) # For XML generation
library(arrow) # For Parquet file handling
##
## Attaching package: 'arrow'
## The following object is masked from 'package:utils':
##
## timestamp
library(readr)
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
library(readr)
inventory <- read_csv("/Users/aaliyahmjh/Downloads/inventory.csv",show_col_types = FALSE)
json_data <- toJSON(inventory, pretty = TRUE)
cat(json_data)
## [
## {
## "Category": "Electronics",
## "Item Name": "Smartphone",
## "Item ID": 101,
## "Brand": "TechBrand",
## "Price": 699.99,
## "Variation ID": "101-A",
## "Variation Details": "Color: Black, Storage: 64GB"
## },
## {
## "Category": "Electronics",
## "Item Name": "Smartphone",
## "Item ID": 101,
## "Brand": "TechBrand",
## "Price": 699.99,
## "Variation ID": "101-B",
## "Variation Details": "Color: White, Storage: 128GB"
## },
## {
## "Category": "Electronics",
## "Item Name": "Laptop",
## "Item ID": 102,
## "Brand": "CompuBrand",
## "Price": 1099.99,
## "Variation ID": "102-A",
## "Variation Details": "Color: Silver, Storage: 256GB"
## },
## {
## "Category": "Electronics",
## "Item Name": "Laptop",
## "Item ID": 102,
## "Brand": "CompuBrand",
## "Price": 1099.99,
## "Variation ID": "102-B",
## "Variation Details": "Color: Space Gray, Storage: 512GB"
## },
## {
## "Category": "Home Appliances",
## "Item Name": "Refrigerator",
## "Item ID": 201,
## "Brand": "HomeCool",
## "Price": 899.99,
## "Variation ID": "201-A",
## "Variation Details": "Color: Stainless Steel, Capacity: 20 cu ft"
## },
## {
## "Category": "Home Appliances",
## "Item Name": "Refrigerator",
## "Item ID": 201,
## "Brand": "HomeCool",
## "Price": 899.99,
## "Variation ID": "201-B",
## "Variation Details": "Color: White, Capacity: 18 cu ft"
## },
## {
## "Category": "Home Appliances",
## "Item Name": "Washing Machine",
## "Item ID": 202,
## "Brand": "CleanTech",
## "Price": 499.99,
## "Variation ID": "202-A",
## "Variation Details": "Type: Front Load, Capacity: 4.5 cu ft"
## },
## {
## "Category": "Home Appliances",
## "Item Name": "Washing Machine",
## "Item ID": 202,
## "Brand": "CleanTech",
## "Price": 499.99,
## "Variation ID": "202-B",
## "Variation Details": "Type: Top Load, Capacity: 5.0 cu ft"
## },
## {
## "Category": "Clothing",
## "Item Name": "T-Shirt",
## "Item ID": 301,
## "Brand": "FashionCo",
## "Price": 19.99,
## "Variation ID": "301-A",
## "Variation Details": "Color: Blue, Size: S"
## },
## {
## "Category": "Clothing",
## "Item Name": "T-Shirt",
## "Item ID": 301,
## "Brand": "FashionCo",
## "Price": 19.99,
## "Variation ID": "301-B",
## "Variation Details": "Color: Red, Size: M"
## },
## {
## "Category": "Clothing",
## "Item Name": "T-Shirt",
## "Item ID": 301,
## "Brand": "FashionCo",
## "Price": 19.99,
## "Variation ID": "301-C",
## "Variation Details": "Color: Green, Size: L"
## },
## {
## "Category": "Clothing",
## "Item Name": "Jeans",
## "Item ID": 302,
## "Brand": "DenimWorks",
## "Price": 49.99,
## "Variation ID": "302-A",
## "Variation Details": "Color: Dark Blue, Size: 32"
## },
## {
## "Category": "Clothing",
## "Item Name": "Jeans",
## "Item ID": 302,
## "Brand": "DenimWorks",
## "Price": 49.99,
## "Variation ID": "302-B",
## "Variation Details": "Color: Light Blue, Size: 34"
## },
## {
## "Category": "Books",
## "Item Name": "Fiction Novel",
## "Item ID": 401,
## "Brand": "-",
## "Price": 14.99,
## "Variation ID": "401-A",
## "Variation Details": "Format: Hardcover, Language: English"
## },
## {
## "Category": "Books",
## "Item Name": "Fiction Novel",
## "Item ID": 401,
## "Brand": "-",
## "Price": 14.99,
## "Variation ID": "401-B",
## "Variation Details": "Format: Paperback, Language: Spanish"
## },
## {
## "Category": "Books",
## "Item Name": "Non-Fiction Guide",
## "Item ID": 402,
## "Brand": "-",
## "Price": 24.99,
## "Variation ID": "402-A",
## "Variation Details": "Format: eBook, Language: English"
## },
## {
## "Category": "Books",
## "Item Name": "Non-Fiction Guide",
## "Item ID": 402,
## "Brand": "-",
## "Price": 24.99,
## "Variation ID": "402-B",
## "Variation Details": "Format: Paperback, Language: French"
## },
## {
## "Category": "Sports Equipment",
## "Item Name": "Basketball",
## "Item ID": 501,
## "Brand": "SportsGear",
## "Price": 29.99,
## "Variation ID": "501-A",
## "Variation Details": "Size: Size 7, Color: Orange"
## },
## {
## "Category": "Sports Equipment",
## "Item Name": "Tennis Racket",
## "Item ID": 502,
## "Brand": "RacketPro",
## "Price": 89.99,
## "Variation ID": "502-A",
## "Variation Details": "Material: Graphite, Color: Black"
## },
## {
## "Category": "Sports Equipment",
## "Item Name": "Tennis Racket",
## "Item ID": 502,
## "Brand": "RacketPro",
## "Price": 89.99,
## "Variation ID": "502-B",
## "Variation Details": "Material: Aluminum, Color: Silver"
## }
## ]
write(json_data, file = "inventory.json")
html_data <- kable(inventory, format = "html")
print(html_data)
## <table>
## <thead>
## <tr>
## <th style="text-align:left;"> Category </th>
## <th style="text-align:left;"> Item Name </th>
## <th style="text-align:right;"> Item ID </th>
## <th style="text-align:left;"> Brand </th>
## <th style="text-align:right;"> Price </th>
## <th style="text-align:left;"> Variation ID </th>
## <th style="text-align:left;"> Variation Details </th>
## </tr>
## </thead>
## <tbody>
## <tr>
## <td style="text-align:left;"> Electronics </td>
## <td style="text-align:left;"> Smartphone </td>
## <td style="text-align:right;"> 101 </td>
## <td style="text-align:left;"> TechBrand </td>
## <td style="text-align:right;"> 699.99 </td>
## <td style="text-align:left;"> 101-A </td>
## <td style="text-align:left;"> Color: Black, Storage: 64GB </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Electronics </td>
## <td style="text-align:left;"> Smartphone </td>
## <td style="text-align:right;"> 101 </td>
## <td style="text-align:left;"> TechBrand </td>
## <td style="text-align:right;"> 699.99 </td>
## <td style="text-align:left;"> 101-B </td>
## <td style="text-align:left;"> Color: White, Storage: 128GB </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Electronics </td>
## <td style="text-align:left;"> Laptop </td>
## <td style="text-align:right;"> 102 </td>
## <td style="text-align:left;"> CompuBrand </td>
## <td style="text-align:right;"> 1099.99 </td>
## <td style="text-align:left;"> 102-A </td>
## <td style="text-align:left;"> Color: Silver, Storage: 256GB </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Electronics </td>
## <td style="text-align:left;"> Laptop </td>
## <td style="text-align:right;"> 102 </td>
## <td style="text-align:left;"> CompuBrand </td>
## <td style="text-align:right;"> 1099.99 </td>
## <td style="text-align:left;"> 102-B </td>
## <td style="text-align:left;"> Color: Space Gray, Storage: 512GB </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Home Appliances </td>
## <td style="text-align:left;"> Refrigerator </td>
## <td style="text-align:right;"> 201 </td>
## <td style="text-align:left;"> HomeCool </td>
## <td style="text-align:right;"> 899.99 </td>
## <td style="text-align:left;"> 201-A </td>
## <td style="text-align:left;"> Color: Stainless Steel, Capacity: 20 cu ft </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Home Appliances </td>
## <td style="text-align:left;"> Refrigerator </td>
## <td style="text-align:right;"> 201 </td>
## <td style="text-align:left;"> HomeCool </td>
## <td style="text-align:right;"> 899.99 </td>
## <td style="text-align:left;"> 201-B </td>
## <td style="text-align:left;"> Color: White, Capacity: 18 cu ft </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Home Appliances </td>
## <td style="text-align:left;"> Washing Machine </td>
## <td style="text-align:right;"> 202 </td>
## <td style="text-align:left;"> CleanTech </td>
## <td style="text-align:right;"> 499.99 </td>
## <td style="text-align:left;"> 202-A </td>
## <td style="text-align:left;"> Type: Front Load, Capacity: 4.5 cu ft </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Home Appliances </td>
## <td style="text-align:left;"> Washing Machine </td>
## <td style="text-align:right;"> 202 </td>
## <td style="text-align:left;"> CleanTech </td>
## <td style="text-align:right;"> 499.99 </td>
## <td style="text-align:left;"> 202-B </td>
## <td style="text-align:left;"> Type: Top Load, Capacity: 5.0 cu ft </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Clothing </td>
## <td style="text-align:left;"> T-Shirt </td>
## <td style="text-align:right;"> 301 </td>
## <td style="text-align:left;"> FashionCo </td>
## <td style="text-align:right;"> 19.99 </td>
## <td style="text-align:left;"> 301-A </td>
## <td style="text-align:left;"> Color: Blue, Size: S </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Clothing </td>
## <td style="text-align:left;"> T-Shirt </td>
## <td style="text-align:right;"> 301 </td>
## <td style="text-align:left;"> FashionCo </td>
## <td style="text-align:right;"> 19.99 </td>
## <td style="text-align:left;"> 301-B </td>
## <td style="text-align:left;"> Color: Red, Size: M </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Clothing </td>
## <td style="text-align:left;"> T-Shirt </td>
## <td style="text-align:right;"> 301 </td>
## <td style="text-align:left;"> FashionCo </td>
## <td style="text-align:right;"> 19.99 </td>
## <td style="text-align:left;"> 301-C </td>
## <td style="text-align:left;"> Color: Green, Size: L </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Clothing </td>
## <td style="text-align:left;"> Jeans </td>
## <td style="text-align:right;"> 302 </td>
## <td style="text-align:left;"> DenimWorks </td>
## <td style="text-align:right;"> 49.99 </td>
## <td style="text-align:left;"> 302-A </td>
## <td style="text-align:left;"> Color: Dark Blue, Size: 32 </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Clothing </td>
## <td style="text-align:left;"> Jeans </td>
## <td style="text-align:right;"> 302 </td>
## <td style="text-align:left;"> DenimWorks </td>
## <td style="text-align:right;"> 49.99 </td>
## <td style="text-align:left;"> 302-B </td>
## <td style="text-align:left;"> Color: Light Blue, Size: 34 </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Books </td>
## <td style="text-align:left;"> Fiction Novel </td>
## <td style="text-align:right;"> 401 </td>
## <td style="text-align:left;"> - </td>
## <td style="text-align:right;"> 14.99 </td>
## <td style="text-align:left;"> 401-A </td>
## <td style="text-align:left;"> Format: Hardcover, Language: English </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Books </td>
## <td style="text-align:left;"> Fiction Novel </td>
## <td style="text-align:right;"> 401 </td>
## <td style="text-align:left;"> - </td>
## <td style="text-align:right;"> 14.99 </td>
## <td style="text-align:left;"> 401-B </td>
## <td style="text-align:left;"> Format: Paperback, Language: Spanish </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Books </td>
## <td style="text-align:left;"> Non-Fiction Guide </td>
## <td style="text-align:right;"> 402 </td>
## <td style="text-align:left;"> - </td>
## <td style="text-align:right;"> 24.99 </td>
## <td style="text-align:left;"> 402-A </td>
## <td style="text-align:left;"> Format: eBook, Language: English </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Books </td>
## <td style="text-align:left;"> Non-Fiction Guide </td>
## <td style="text-align:right;"> 402 </td>
## <td style="text-align:left;"> - </td>
## <td style="text-align:right;"> 24.99 </td>
## <td style="text-align:left;"> 402-B </td>
## <td style="text-align:left;"> Format: Paperback, Language: French </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Sports Equipment </td>
## <td style="text-align:left;"> Basketball </td>
## <td style="text-align:right;"> 501 </td>
## <td style="text-align:left;"> SportsGear </td>
## <td style="text-align:right;"> 29.99 </td>
## <td style="text-align:left;"> 501-A </td>
## <td style="text-align:left;"> Size: Size 7, Color: Orange </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Sports Equipment </td>
## <td style="text-align:left;"> Tennis Racket </td>
## <td style="text-align:right;"> 502 </td>
## <td style="text-align:left;"> RacketPro </td>
## <td style="text-align:right;"> 89.99 </td>
## <td style="text-align:left;"> 502-A </td>
## <td style="text-align:left;"> Material: Graphite, Color: Black </td>
## </tr>
## <tr>
## <td style="text-align:left;"> Sports Equipment </td>
## <td style="text-align:left;"> Tennis Racket </td>
## <td style="text-align:right;"> 502 </td>
## <td style="text-align:left;"> RacketPro </td>
## <td style="text-align:right;"> 89.99 </td>
## <td style="text-align:left;"> 502-B </td>
## <td style="text-align:left;"> Material: Aluminum, Color: Silver </td>
## </tr>
## </tbody>
## </table>
write(html_data, file = "inventory.html")
write_parquet(inventory, "inventory.parquet")
names(inventory) <- gsub(" ", "_", names(inventory))
suppressWarnings({
xml_data <- newXMLNode("Inventory")
for(i in 1:nrow(inventory)) {
item <- newXMLNode("Item", parent = xml_data)
for(col in names(inventory)) {
newXMLNode(col, inventory[i, col], parent = item)
}
}
xml_string <- saveXML(xml_data)
cat(xml_string)
})
## <Inventory>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Smartphone</Item_Name>
## <Item_ID>101</Item_ID>
## <Brand>TechBrand</Brand>
## <Price>699.99</Price>
## <Variation_ID>101-A</Variation_ID>
## <Variation_Details>Color: Black, Storage: 64GB</Variation_Details>
## </Item>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Smartphone</Item_Name>
## <Item_ID>101</Item_ID>
## <Brand>TechBrand</Brand>
## <Price>699.99</Price>
## <Variation_ID>101-B</Variation_ID>
## <Variation_Details>Color: White, Storage: 128GB</Variation_Details>
## </Item>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Laptop</Item_Name>
## <Item_ID>102</Item_ID>
## <Brand>CompuBrand</Brand>
## <Price>1099.99</Price>
## <Variation_ID>102-A</Variation_ID>
## <Variation_Details>Color: Silver, Storage: 256GB</Variation_Details>
## </Item>
## <Item>
## <Category>Electronics</Category>
## <Item_Name>Laptop</Item_Name>
## <Item_ID>102</Item_ID>
## <Brand>CompuBrand</Brand>
## <Price>1099.99</Price>
## <Variation_ID>102-B</Variation_ID>
## <Variation_Details>Color: Space Gray, Storage: 512GB</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Refrigerator</Item_Name>
## <Item_ID>201</Item_ID>
## <Brand>HomeCool</Brand>
## <Price>899.99</Price>
## <Variation_ID>201-A</Variation_ID>
## <Variation_Details>Color: Stainless Steel, Capacity: 20 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Refrigerator</Item_Name>
## <Item_ID>201</Item_ID>
## <Brand>HomeCool</Brand>
## <Price>899.99</Price>
## <Variation_ID>201-B</Variation_ID>
## <Variation_Details>Color: White, Capacity: 18 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Washing Machine</Item_Name>
## <Item_ID>202</Item_ID>
## <Brand>CleanTech</Brand>
## <Price>499.99</Price>
## <Variation_ID>202-A</Variation_ID>
## <Variation_Details>Type: Front Load, Capacity: 4.5 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Home Appliances</Category>
## <Item_Name>Washing Machine</Item_Name>
## <Item_ID>202</Item_ID>
## <Brand>CleanTech</Brand>
## <Price>499.99</Price>
## <Variation_ID>202-B</Variation_ID>
## <Variation_Details>Type: Top Load, Capacity: 5.0 cu ft</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>T-Shirt</Item_Name>
## <Item_ID>301</Item_ID>
## <Brand>FashionCo</Brand>
## <Price>19.99</Price>
## <Variation_ID>301-A</Variation_ID>
## <Variation_Details>Color: Blue, Size: S</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>T-Shirt</Item_Name>
## <Item_ID>301</Item_ID>
## <Brand>FashionCo</Brand>
## <Price>19.99</Price>
## <Variation_ID>301-B</Variation_ID>
## <Variation_Details>Color: Red, Size: M</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>T-Shirt</Item_Name>
## <Item_ID>301</Item_ID>
## <Brand>FashionCo</Brand>
## <Price>19.99</Price>
## <Variation_ID>301-C</Variation_ID>
## <Variation_Details>Color: Green, Size: L</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>Jeans</Item_Name>
## <Item_ID>302</Item_ID>
## <Brand>DenimWorks</Brand>
## <Price>49.99</Price>
## <Variation_ID>302-A</Variation_ID>
## <Variation_Details>Color: Dark Blue, Size: 32</Variation_Details>
## </Item>
## <Item>
## <Category>Clothing</Category>
## <Item_Name>Jeans</Item_Name>
## <Item_ID>302</Item_ID>
## <Brand>DenimWorks</Brand>
## <Price>49.99</Price>
## <Variation_ID>302-B</Variation_ID>
## <Variation_Details>Color: Light Blue, Size: 34</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Fiction Novel</Item_Name>
## <Item_ID>401</Item_ID>
## <Brand>-</Brand>
## <Price>14.99</Price>
## <Variation_ID>401-A</Variation_ID>
## <Variation_Details>Format: Hardcover, Language: English</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Fiction Novel</Item_Name>
## <Item_ID>401</Item_ID>
## <Brand>-</Brand>
## <Price>14.99</Price>
## <Variation_ID>401-B</Variation_ID>
## <Variation_Details>Format: Paperback, Language: Spanish</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Non-Fiction Guide</Item_Name>
## <Item_ID>402</Item_ID>
## <Brand>-</Brand>
## <Price>24.99</Price>
## <Variation_ID>402-A</Variation_ID>
## <Variation_Details>Format: eBook, Language: English</Variation_Details>
## </Item>
## <Item>
## <Category>Books</Category>
## <Item_Name>Non-Fiction Guide</Item_Name>
## <Item_ID>402</Item_ID>
## <Brand>-</Brand>
## <Price>24.99</Price>
## <Variation_ID>402-B</Variation_ID>
## <Variation_Details>Format: Paperback, Language: French</Variation_Details>
## </Item>
## <Item>
## <Category>Sports Equipment</Category>
## <Item_Name>Basketball</Item_Name>
## <Item_ID>501</Item_ID>
## <Brand>SportsGear</Brand>
## <Price>29.99</Price>
## <Variation_ID>501-A</Variation_ID>
## <Variation_Details>Size: Size 7, Color: Orange</Variation_Details>
## </Item>
## <Item>
## <Category>Sports Equipment</Category>
## <Item_Name>Tennis Racket</Item_Name>
## <Item_ID>502</Item_ID>
## <Brand>RacketPro</Brand>
## <Price>89.99</Price>
## <Variation_ID>502-A</Variation_ID>
## <Variation_Details>Material: Graphite, Color: Black</Variation_Details>
## </Item>
## <Item>
## <Category>Sports Equipment</Category>
## <Item_Name>Tennis Racket</Item_Name>
## <Item_ID>502</Item_ID>
## <Brand>RacketPro</Brand>
## <Price>89.99</Price>
## <Variation_ID>502-B</Variation_ID>
## <Variation_Details>Material: Aluminum, Color: Silver</Variation_Details>
## </Item>
## </Inventory>
write(xml_string, file = "inventory.xml")
I wanted to check the average, minimum and maximum price for each category. As expected, Electronics were the most expensive with books being least expensive.
category_summary <- inventory %>%
group_by(Category) %>%
summarise(
Count = n(),
Avg_Price = mean(Price),
Min_Price = min(Price),
Max_Price = max(Price)
)
print(category_summary)
## # A tibble: 5 × 5
## Category Count Avg_Price Min_Price Max_Price
## <chr> <int> <dbl> <dbl> <dbl>
## 1 Books 4 20.0 15.0 25.0
## 2 Clothing 5 32.0 20.0 50.0
## 3 Electronics 4 900. 700. 1100.
## 4 Home Appliances 4 700. 500. 900.
## 5 Sports Equipment 3 70.0 30.0 90.0
I examined how many types of variations there were for each item. Most had 2 variations per item with T-shirts having 3 (most variations) and Basketball just having 1.
item_variations <- inventory %>%
group_by(Item_ID, Item_Name) %>%
summarise(Variations = n())
## `summarise()` has grouped output by 'Item_ID'. You can override using the
## `.groups` argument.
print(item_variations)
## # A tibble: 10 × 3
## # Groups: Item_ID [10]
## Item_ID Item_Name Variations
## <dbl> <chr> <int>
## 1 101 Smartphone 2
## 2 102 Laptop 2
## 3 201 Refrigerator 2
## 4 202 Washing Machine 2
## 5 301 T-Shirt 3
## 6 302 Jeans 2
## 7 401 Fiction Novel 2
## 8 402 Non-Fiction Guide 2
## 9 501 Basketball 1
## 10 502 Tennis Racket 2