Data cleansing and transformation
The dataset consists of 8,595 rows and 65 columns. The structure of
the columns reveals a combination of categorical and numerical
variables, with 57 of the columns being of character type and 8 of
numeric type. Some key variables include information about the domain,
account name, business unit code, primary reference numbers, carriers,
transportation modes, order types, service levels, load numbers,
quantities, handling units, management, intermediate stops, and
more.
Before proceeding with the analysis, changes will be made to the data
types to ensure consistency and appropriateness of the variables.
Appropriate conversions will be considered to enhance efficiency in the
analysis and interpretation of results. The goal is to provide a solid
and homogeneous database to address specific questions about the
logistics operations of the International Automotive Components (IAC)
plant in Toluca throughout the year 2023.
datos<-read.csv('~/Desktop/prueba/108/RPT00108-Basic-Load-Info23.csv')
datos_filt<-datos%>%filter(Business.Unit.Code=='TOLUCA')
col_erase<-c('Contract.Number.s.','Secondary.Reference.s.','Customer.PO.Number','Destination.Loading.Type','Transaction.Adjust.Management','Line.of.Business','Non.Managed','Oversize.Indicator..Y.N.','Sales.Order.Number','SO.Project.ID','Duties')
datos_filt<-datos_filt%>%select(-one_of(col_erase))
skim(datos_filt)
Data summary
|
Name
|
datos_filt
|
|
Number of rows
|
8595
|
|
Number of columns
|
65
|
|
_______________________
|
|
|
Column type frequency:
|
|
|
character
|
57
|
|
numeric
|
8
|
|
________________________
|
|
|
Group variables
|
None
|
Variable type: character
|
skim_variable
|
n_missing
|
complete_rate
|
min
|
max
|
empty
|
n_unique
|
whitespace
|
|
Domain.Name
|
0
|
1
|
13
|
13
|
0
|
1
|
0
|
|
Account.Name
|
0
|
1
|
13
|
13
|
0
|
1
|
0
|
|
Business.Unit.Code
|
0
|
1
|
6
|
6
|
0
|
1
|
0
|
|
Primary.Reference.Number.s.
|
0
|
1
|
3
|
184
|
0
|
7621
|
0
|
|
Carrier.SCAC
|
0
|
1
|
0
|
5
|
1694
|
27
|
0
|
|
Carrier.Name
|
0
|
1
|
15
|
48
|
0
|
26
|
0
|
|
Mode.Provider.Selection.Method
|
0
|
1
|
0
|
20
|
1694
|
4
|
0
|
|
Mode.Type
|
0
|
1
|
2
|
5
|
0
|
3
|
0
|
|
Order.Type.s.
|
0
|
1
|
6
|
31
|
0
|
7
|
0
|
|
Service.Level
|
2
|
1
|
8
|
9
|
0
|
2
|
0
|
|
Bill.To.Code
|
0
|
1
|
0
|
8
|
1710
|
3
|
0
|
|
Miles
|
0
|
1
|
1
|
5
|
0
|
493
|
0
|
|
Volume
|
0
|
1
|
0
|
7
|
860
|
422
|
0
|
|
Weight
|
0
|
1
|
0
|
10
|
4
|
1316
|
0
|
|
Weight.UOM
|
0
|
1
|
0
|
3
|
4
|
3
|
0
|
|
Equip.Type
|
0
|
1
|
3
|
25
|
0
|
15
|
0
|
|
Shipper.Code
|
0
|
1
|
2
|
30
|
0
|
301
|
0
|
|
Shipper.Name
|
0
|
1
|
3
|
38
|
0
|
297
|
0
|
|
Shipper.City
|
0
|
1
|
4
|
29
|
0
|
170
|
0
|
|
Shipper.State
|
0
|
1
|
2
|
2
|
0
|
48
|
0
|
|
Shipper.Zip
|
0
|
1
|
3
|
7
|
0
|
212
|
0
|
|
Scheduled.Ship.Date
|
0
|
1
|
8
|
10
|
0
|
350
|
0
|
|
Actual.Ship.Date
|
0
|
1
|
0
|
10
|
1738
|
354
|
0
|
|
Origin.Loading.Type
|
0
|
1
|
0
|
10
|
7428
|
4
|
0
|
|
Top.Customer.Name
|
0
|
1
|
5
|
5
|
0
|
1
|
0
|
|
Receiver.Code
|
0
|
1
|
2
|
26
|
0
|
73
|
0
|
|
Receiver.Name
|
0
|
1
|
4
|
38
|
0
|
72
|
0
|
|
Receiver.City
|
0
|
1
|
4
|
19
|
0
|
44
|
0
|
|
Receiver.State
|
0
|
1
|
2
|
2
|
0
|
23
|
0
|
|
Receiver.Zip
|
0
|
1
|
5
|
6
|
0
|
54
|
0
|
|
Scheduled.Delivery.Date
|
0
|
1
|
8
|
10
|
0
|
374
|
0
|
|
Actual.Delivery.Date
|
0
|
1
|
0
|
10
|
1863
|
356
|
0
|
|
Tender.Accept.Date
|
0
|
1
|
0
|
10
|
1913
|
335
|
0
|
|
Ready.For.Books.Date
|
0
|
1
|
0
|
10
|
140
|
355
|
0
|
|
Line.Haul
|
0
|
1
|
1
|
10
|
0
|
1169
|
0
|
|
Fuel.Surcharge
|
0
|
1
|
1
|
7
|
0
|
872
|
0
|
|
Accessorials
|
0
|
1
|
1
|
11
|
0
|
728
|
0
|
|
Freight.Cost
|
0
|
1
|
1
|
11
|
0
|
1937
|
0
|
|
Currency
|
0
|
1
|
0
|
3
|
1710
|
3
|
0
|
|
Cost.Per.Ton
|
0
|
1
|
1
|
14
|
0
|
2793
|
0
|
|
Created.By
|
0
|
1
|
11
|
24
|
0
|
26
|
0
|
|
Load.Created.Datetime
|
0
|
1
|
13
|
22
|
0
|
2140
|
0
|
|
ME.Status
|
0
|
1
|
7
|
13
|
0
|
7
|
0
|
|
Haz..Materials
|
0
|
1
|
1
|
1
|
0
|
2
|
0
|
|
Products
|
0
|
1
|
0
|
58
|
7253
|
92
|
0
|
|
Product.Description
|
0
|
1
|
0
|
99
|
7274
|
481
|
0
|
|
Method.of.Payment
|
0
|
1
|
2
|
2
|
0
|
4
|
0
|
|
HOT
|
0
|
1
|
1
|
1
|
0
|
2
|
0
|
|
Pro.Number
|
0
|
1
|
0
|
75
|
7170
|
1414
|
0
|
|
Receiver.Region
|
0
|
1
|
7
|
9
|
0
|
4
|
0
|
|
Minimum.Charge.Indicator
|
0
|
1
|
1
|
1
|
0
|
2
|
0
|
|
Shipment.Created.By
|
0
|
1
|
0
|
11
|
118
|
3
|
0
|
|
Created.by
|
0
|
1
|
10
|
23
|
0
|
26
|
0
|
|
User.Type
|
0
|
1
|
8
|
8
|
0
|
2
|
0
|
|
Order.Created.By
|
0
|
1
|
0
|
23
|
118
|
30
|
0
|
|
Order.Method
|
0
|
1
|
0
|
11
|
118
|
3
|
0
|
|
Order.User.Type
|
0
|
1
|
0
|
8
|
118
|
3
|
0
|
Variable type: numeric
|
skim_variable
|
n_missing
|
complete_rate
|
mean
|
sd
|
p0
|
p25
|
p50
|
p75
|
p100
|
hist
|
|
Load.Number
|
0
|
1.00
|
8.61932e+08
|
6397926.10
|
850106482
|
856659844
|
862025825
|
867491292
|
873826271
|
▆▇▇▇▆
|
|
Quantity
|
427
|
0.95
|
2.27276e+03
|
1581.01
|
0
|
2500
|
2500
|
2500
|
76500
|
▇▁▁▁▁
|
|
Handling.Units
|
12
|
1.00
|
1.40400e+01
|
41.38
|
0
|
3
|
8
|
24
|
2600
|
▇▁▁▁▁
|
|
Management
|
0
|
1.00
|
0.00000e+00
|
0.00
|
0
|
0
|
0
|
0
|
0
|
▁▁▇▁▁
|
|
Intermediate.Stops…Pickup
|
0
|
1.00
|
8.00000e-02
|
0.38
|
0
|
0
|
0
|
0
|
4
|
▇▁▁▁▁
|
|
Intermediate.Stops…Delivery
|
0
|
1.00
|
2.00000e-02
|
0.15
|
0
|
0
|
0
|
0
|
2
|
▇▁▁▁▁
|
|
Consource.Indicator
|
0
|
1.00
|
0.00000e+00
|
0.00
|
0
|
0
|
0
|
0
|
0
|
▁▁▇▁▁
|
|
Customer.Routed
|
0
|
1.00
|
0.00000e+00
|
0.00
|
0
|
0
|
0
|
0
|
0
|
▁▁▇▁▁
|
datos_filt<-datos_filt%>%
mutate(AMPM=substr(Load.Created.Datetime,nchar(Load.Created.Datetime)-1,nchar(Load.Created.Datetime)),
Load.Created.Datetime=substr(Load.Created.Datetime,1,nchar(Load.Created.Datetime)-2))
datos_filt<-as.data.table(datos_filt)
datos_filt$Load.Created.Datetime1<-datos_filt$Load.Created.Datetime
datos_filt$Load.Created.Datetime1<-trimws(datos_filt$Load.Created.Datetime1,which='right')
datos_filt$Load.Created.Datetime1<-ifelse(nchar(datos_filt$Load.Created.Datetime1)<8,
str_pad(datos_filt$Load.Created.Datetime1,width=8,side='left',pad='0'),
datos_filt$Load.Created.Datetime1)
datos_filt<-datos_filt %>%
mutate(Hour=str_sub(Load.Created.Datetime1,nchar(Load.Created.Datetime1)-7,nchar(Load.Created.Datetime1)-6),
Date=str_sub(Load.Created.Datetime1,1,nchar(Load.Created.Datetime1)-9),
Load.Created.Datetime1=sprintf('%02d%s',ifelse(AMPM=='PM',as.numeric(Hour)+12,as.numeric(Hour)),
str_sub(Load.Created.Datetime1,nchar(Load.Created.Datetime1)-5)))
datos_filt$Date<-ifelse(str_sub(datos_filt$Date,-1)=='2',paste0(datos_filt$Date,'3'),datos_filt$Date)
datos_filt$Date<-ifelse(nchar(datos_filt$Date)<=9,paste0('0',datos_filt$Date),datos_filt$Date)
datos_filt$Date<-ifelse(nchar(datos_filt$Date)==9,paste0(substr(datos_filt$Date,1,3),'0',substr(datos_filt$Date,4,9)),datos_filt$Date)
datos_filt$Load.Created.Datetime1<-ifelse(nchar(datos_filt$Load.Created.Datetime1)<=5,str_c(datos_filt$Load.Created.Datetime1,':00'),datos_filt$Load.Created.Datetime1)
datos_filt<-datos_filt%>%mutate(Load.Created.Datetime1=ifelse(str_sub(Load.Created.Datetime1,1,2)=='24',paste0('23',str_sub(Load.Created.Datetime1,3)),Load.Created.Datetime1))
datos_filt<-datos_filt%>%mutate(Load.Created.Datetime2=paste(Date,Load.Created.Datetime1,sep=' '))
datos_filt$Date<-NULL
datos_filt$Hour<-NULL
datos_filt$AMPM<-NULL
datos_filt$Load.Created.Datetime1<-NULL
datos_filt$Load.Created.Datetime<-NULL
colnames(datos_filt)[colnames(datos_filt)=='Load.Created.Datetime2']<-'Load.Created.Datetime'
datos_filt$Load.Created.Datetime<-as.POSIXct(datos_filt$Load.Created.Datetime,format='%m/%d/%Y %H:%M:%S',tz='UTC',na.rm = TRUE)
datos_filt$Scheduled.Ship.Date<-as.Date(datos_filt$Scheduled.Ship.Date,format='%m/%d/%Y')
datos_filt$Actual.Ship.Date<-as.Date(datos_filt$Actual.Ship.Date,format='%m/%d/%Y')
datos_filt$Scheduled.Delivery.Date<-as.Date(datos_filt$Scheduled.Delivery.Date,format='%m/%d/%Y')
datos_filt$Actual.Delivery.Date<-as.Date(datos_filt$Actual.Delivery.Date,format='%m/%d/%Y')
datos_filt$Tender.Accept.Date<-as.Date(datos_filt$Tender.Accept.Date,format='%m/%d/%Y')
datos_filt$Ready.For.Books.Date<-as.Date(datos_filt$Ready.For.Books.Date,format='%m/%d/%Y')
datos_filt$Load.Number<-as.character(datos_filt$Load.Number)
datos_filt$Miles<-gsub(',','',datos_filt$Miles)
datos_filt$Miles<-as.numeric(datos_filt$Miles)
datos_filt$Volume<-gsub(',','',datos_filt$Volume)
datos_filt$Volume<-as.numeric(datos_filt$Volume)
datos_filt$Weight<-gsub(',','',datos_filt$Weight)
datos_filt$Weight<-as.numeric(datos_filt$Weight)
datos_filt$Line.Haul<-gsub(',','',datos_filt$Line.Haul)
datos_filt$Line.Haul<-as.numeric(gsub('\\$','',datos_filt$Line.Haul))
datos_filt$Fuel.Surcharge<-gsub(',','',datos_filt$Fuel.Surcharge)
datos_filt$Fuel.Surcharge<-as.numeric(gsub('\\$','',datos_filt$Fuel.Surcharge))
datos_filt$Accessorials<-gsub(',','',datos_filt$Accessorials)
datos_filt$Accessorials<-as.numeric(gsub('\\$','',datos_filt$Accessorials))
datos_filt$Freight.Cost<-gsub(',','',datos_filt$Freight.Cost)
datos_filt$Freight.Cost<-as.numeric(gsub('\\$','',datos_filt$Freight.Cost))
datos_filt$Cost.Per.Ton<-gsub(',','',datos_filt$Cost.Per.Ton)
datos_filt$Cost.Per.Ton<-as.numeric(gsub('\\$','',datos_filt$Cost.Per.Ton))
datos_filt$Carrier.Name<-gsub('LOESA EXPEDITED SERVICES LLC','LOESA EXPEDITED SERVICES SA DE CV',datos_filt$Carrier.Name)
datos_filt$Carrier.Name<-gsub('TRANSPLACE MEXICO, LLC','TRANSPLACE DE MEXICO',datos_filt$Carrier.Name)
datos_filt$Mode.Type[grepl("PROTRANS INTERNATIONAL INC",datos_filt$Carrier.Name)]<-"LTL"
#Exchange rate 17.0492 (Banxico, 2024)
#https://www.banxico.org.mx/
datos_filt$Cost.Per.Ton[datos_filt$Currency=='MXN']<-datos_filt$Cost.Per.Ton[datos_filt$Currency=='MXN']/17.0492
datos_filt$Freight.Cost[datos_filt$Currency=='MXN']<-datos_filt$Freight.Cost[datos_filt$Currency=='MXN']/17.0492
datos_filt$Line.Haul[datos_filt$Currency=='MXN']<-datos_filt$Line.Haul[datos_filt$Currency=='MXN']/17.0492
datos_filt$Currency[datos_filt$Currency=='MXN']<-'USD'
datos_filt$Currency[datos_filt$Currency=='']<-'USD'
ocean<-datos_filt[grepl('OCEAN',datos_filt$Mode.Type,ignore.case=TRUE,fixed=TRUE),]
ltl<-datos_filt[grepl('LTL',datos_filt$Mode.Type,ignore.case=TRUE,fixed=TRUE),]
tl<-datos_filt[grepl('TL',datos_filt$Mode.Type,ignore.case=TRUE),]
tl<-datos_filt[grepl('^TL$',datos_filt$Mode.Type,ignore.case=TRUE),]
unique(tl$Mode.Type)
## [1] "TL"
Here is the optimized data structure that will facilitate the
detailed analysis of the plant, consisting of 8,595 records distributed
across 65 columns.
glimpse(datos_filt)
## Rows: 8,595
## Columns: 65
## $ Domain.Name <chr> "IAC GROUP INC", "IAC GROUP INC", "IAC …
## $ Account.Name <chr> "IAC GROUP INC", "IAC GROUP INC", "IAC …
## $ Business.Unit.Code <chr> "TOLUCA", "TOLUCA", "TOLUCA", "TOLUCA",…
## $ Load.Number <chr> "851547493", "852870092", "852871161", …
## $ Primary.Reference.Number.s. <chr> "TOL0208-1_326_23_4; ", "TOL0200-1_153_…
## $ Carrier.SCAC <chr> "ICAO", "038B", "038B", "PNII", "", "PN…
## $ Carrier.Name <chr> "ICAT LOGISTICS INC", "DSV AIR & SEA SA…
## $ Mode.Provider.Selection.Method <chr> "ME Manual Assignment", "ME Manual Assi…
## $ Mode.Type <chr> "OCEAN", "OCEAN", "OCEAN", "LTL", "LTL"…
## $ Order.Type.s. <chr> "INBOUND", "INBOUND", "INBOUND", "INBOU…
## $ Service.Level <chr> "Standard", "Standard", "Standard", "St…
## $ Bill.To.Code <chr> "IACTOLUO", "IACTOLUO", "IACTOLUO", "IA…
## $ Miles <dbl> 742, 201, 605, 1550, 1551, 153, 1482, 1…
## $ Volume <dbl> 1280, 128, 384, 128, 64, 128, 64, 384, …
## $ Weight <dbl> 4000, 400, 1200, 718, 562, 2017, 1500, …
## $ Weight.UOM <chr> "LBS", "LBS", "LBS", "LBS", "LBS", "LBS…
## $ Quantity <int> 2500, 2500, 2500, 2500, 2500, 2500, 250…
## $ Handling.Units <int> 20, 2, 6, 1, 1, 2, 1, 6, 1, 6, 1, 1, 1,…
## $ Equip.Type <chr> "20 FT CONTAINER", "20 FT CONTAINER", "…
## $ Shipper.Code <chr> "2053334", "2054207", "MURTRA SWEDEN", …
## $ Shipper.Name <chr> "FUXIN DARE AUTOMOTIVE PARTS: 02053334"…
## $ Shipper.City <chr> "SHENZHEN CITY", "BIELSKO-BIALA", "YSTA…
## $ Shipper.State <chr> "GD", "PL", "SE", "MI", "OH", "TX", "NC…
## $ Shipper.Zip <chr> "518046", "43-300", "271 39", "48116", …
## $ Scheduled.Ship.Date <date> 0023-03-05, 0023-03-01, 0023-03-10, 00…
## $ Actual.Ship.Date <date> 0023-03-08, 0023-03-01, 0023-03-10, 00…
## $ Origin.Loading.Type <chr> "", "", "", "", "", "", "", "", "", "",…
## $ Top.Customer.Name <chr> "OTHER", "OTHER", "OTHER", "OTHER", "OT…
## $ Receiver.Code <chr> "OG5", "OG5", "OG5", "DICEX INTERNATION…
## $ Receiver.Name <chr> "IACNA TOLUCA", "IACNA TOLUCA", "IACNA …
## $ Receiver.City <chr> "TOLUCA", "TOLUCA", "TOLUCA", "LAREDO",…
## $ Receiver.State <chr> "MX", "MX", "MX", "TX", "TX", "TX", "TX…
## $ Receiver.Zip <chr> "50010", "50010", "50010", "78045", "78…
## $ Scheduled.Delivery.Date <date> 2023-04-14, 0023-03-06, 0023-04-11, 00…
## $ Actual.Delivery.Date <date> 2023-04-14, 2023-03-27, 0023-04-11, 00…
## $ Tender.Accept.Date <date> 0023-03-03, 0023-02-08, 0023-02-08, 20…
## $ Ready.For.Books.Date <date> 0023-04-05, 2023-03-14, 2023-03-14, 20…
## $ Line.Haul <dbl> 13145.000, 2365.700, 2239.000, 0.000, 0…
## $ Fuel.Surcharge <dbl> 0.00, 0.00, 0.00, 0.00, 0.00, 30.00, 0.…
## $ Management <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ Accessorials <dbl> 0.0, 0.0, 0.0, 50.0, 0.0, 10.0, 0.0, 0.…
## $ Freight.Cost <dbl> 13145.000, 2365.700, 2239.000, 50.000, …
## $ Currency <chr> "USD", "USD", "USD", "USD", "USD", "USD…
## $ Cost.Per.Ton <dbl> 6572.5000, 11828.5000, 3731.6700, 0.000…
## $ Created.By <chr> "Cardoso Rojas, Nicole", "Cardoso Rojas…
## $ Intermediate.Stops...Pickup <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ Intermediate.Stops...Delivery <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ ME.Status <chr> "DELIVERED", "DELIVERED", "DELIVERED", …
## $ Haz..Materials <chr> "N", "N", "N", "N", "N", "N", "N", "N",…
## $ Products <chr> "", "", "", "", "", "", "", "", "L03060…
## $ Product.Description <chr> "", "", "", "Carrier Northfield Truckin…
## $ Method.of.Payment <chr> "CC", "CC", "CC", "TP", "TP", "TP", "TP…
## $ HOT <chr> "N", "N", "N", "N", "N", "N", "N", "N",…
## $ Pro.Number <chr> "", "", "", "S14053515; S14099756; ", "…
## $ Receiver.Region <chr> "UNKNOWN", "UNKNOWN", "UNKNOWN", "SOUTH…
## $ Consource.Indicator <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ Customer.Routed <int> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
## $ Minimum.Charge.Indicator <chr> "N", "N", "N", "N", "N", "N", "N", "N",…
## $ Shipment.Created.By <chr> "UI_IMPORT", "UI_IMPORT", "UI_IMPORT", …
## $ Created.by <chr> "Nicole Cardoso Rojas", "Nicole Cardoso…
## $ User.Type <chr> "Internal", "Internal", "Internal", "In…
## $ Order.Created.By <chr> "Marijose Obaya", "Marijose Obaya", "Ni…
## $ Order.Method <chr> "UI_IMPORT", "UI_IMPORT", "UI_IMPORT", …
## $ Order.User.Type <chr> "Internal", "Internal", "Internal", "In…
## $ Load.Created.Datetime <dttm> 2023-01-18 19:08:18, NA, NA, 2023-02-2…
#write.csv(datos_filt,'clean-database-iac-toluca.csv',row.names=FALSE)