Setting the working directory
#setwd("F:/R Course/Datasets")
- Given the files Items.csv, Orders.csv and Ord_Details.csv in the folder datasets, merge them with appropriate keys to form a combined data.
library(reshape2)
orders <- read.csv("F:/R Course/Datasets/Orders.csv",stringsAsFactors = F)
items <- read.csv("F:/R Course/Datasets/Items.csv")
ord_details <- read.csv("F:/R Course/Datasets/Ord_Details.csv")
ords <- merge(orders,ord_details,by="Order.ID")
comb <- merge(ords,items,by="Item.ID")
head(comb)
## Item.ID Order.ID Order.Date.x Place.of.Shipment Payment.Terms Qty
## 1 121 001 32 90 027 11-Dec-11 Pune Online 18
## 2 121 001 32 90 012 14-Apr-11 Raigad Online 35
## 3 121 001 32 90 045 10-Oct-12 Ratnagiri Cheque 36
## 4 121 001 32 90 023 12-Oct-11 Raigad Online 31
## 5 121 001 32 90 064 12-Jun-13 Aurangabad Cash 26
## 6 121 001 32 90 046 12-Nov-12 Raigad Cash 38
## Order.Date.y Place Item.Price Line.Total
## 1 NA NA 69 1242
## 2 NA NA 69 2415
## 3 NA NA 69 2484
## 4 NA NA 69 2139
## 5 NA NA 69 1794
## 6 NA NA 69 2622
## Item.Name Item.Type Brand Price UOM
## 1 Parker Quink Roller Ball Pen Refill, Blue Pen Parker 69 Piece
## 2 Parker Quink Roller Ball Pen Refill, Blue Pen Parker 69 Piece
## 3 Parker Quink Roller Ball Pen Refill, Blue Pen Parker 69 Piece
## 4 Parker Quink Roller Ball Pen Refill, Blue Pen Parker 69 Piece
## 5 Parker Quink Roller Ball Pen Refill, Blue Pen Parker 69 Piece
## 6 Parker Quink Roller Ball Pen Refill, Blue Pen Parker 69 Piece
- From the data generated in task no. 1, extract Day, Month and Year from the column Order.Date and create separate columns namely Day, Month and Year and store it in the same dataset only
orders$Order.Date <- as.Date(orders$Order.Date,
format = "%d-%b-%y")
orders$Order.Date
## [1] "2010-12-31" "2011-01-06" "2011-01-14" "2011-02-18" "2011-02-19"
## [6] "2011-03-01" "2011-03-04" "2011-03-15" "2011-03-19" "2011-03-29"
## [11] "2011-04-12" "2011-04-14" "2011-05-18" "2011-05-23" "2011-06-11"
## [16] "2011-06-13" "2011-07-13" "2011-08-14" "2011-08-19" "2011-08-19"
## [21] "2011-09-23" "2011-09-28" "2011-10-12" "2011-11-01" "2011-11-13"
## [26] "2011-11-20" "2011-12-11" "2011-12-14" "2011-12-30" "2012-01-01"
## [31] "2012-01-23" "2012-01-24" "2012-03-13" "2012-03-18" "2012-03-30"
## [36] "2012-04-21" "2012-04-22" "2012-05-14" "2012-05-15" "2012-06-19"
## [41] "2012-07-23" "2012-07-30" "2012-07-12" "2012-08-14" "2012-10-10"
## [46] "2012-11-12" "2012-11-13" "2012-11-23" "2012-12-14" "2012-12-19"
## [51] "2012-12-23" "2013-01-13" "2013-01-13" "2013-02-15" "2013-02-11"
## [56] "2013-02-13" "2013-03-01" "2013-03-13" "2013-04-14" "2013-04-14"
## [61] "2013-04-24" "2013-05-13" "2013-05-14" "2013-06-12" "2013-07-11"
## [66] "2013-07-13" "2013-07-23" "2013-08-02" "2013-09-04" "2013-09-07"