1 Introduction
Background
Data science requires automation using functions and loops to process data efficiently.
Objectives
- Apply functions and loops
- Simulate datasets
- Perform visualization
2 Dynamic Multi-Formula Function
## x linear quadratic cubic expo
## 1 1 3 4 1 2
## 2 2 5 9 8 4
## 3 3 7 16 27 8
## 4 4 9 25 64 16
## 5 5 11 36 125 32
## 6 6 13 49 216 64
## 7 7 15 64 343 128
## 8 8 17 81 512 256
## 9 9 19 100 729 512
## 10 10 21 121 1000 1024
## 11 11 23 144 1331 2048
## 12 12 25 169 1728 4096
## 13 13 27 196 2197 8192
## 14 14 29 225 2744 16384
## 15 15 31 256 3375 32768
## 16 16 33 289 4096 65536
## 17 17 35 324 4913 131072
## 18 18 37 361 5832 262144
## 19 19 39 400 6859 524288
## 20 20 41 441 8000 1048576
3 Nested Simulation: Multi-Sales & Discounts
## salesperson day sales discount
## 1 1 1 514 0.05
## 2 2 1 562 0.05
## 3 3 1 278 0.05
## 4 4 1 625 0.05
## 5 5 1 294 0.05
## 6 1 2 917 0.20
4 Multi-Level Performance Categorization
## scores category
## 1 51 Average
## 2 52 Average
## 3 57 Average
## 4 72 Very Good
## 5 96 Excellent
## 6 66 Good
## 7 64 Good
## 8 77 Very Good
## 9 60 Average
## 10 54 Average
## 11 80 Very Good
## 12 86 Excellent
## 13 65 Good
## 14 99 Excellent
## 15 70 Good
## 16 55 Average
## 17 91 Excellent
## 18 69 Good
## 19 45 Poor
## 20 82 Excellent
## 21 47 Poor
## 22 61 Good
## 23 61 Good
## 24 78 Very Good
## 25 70 Good
## 26 87 Excellent
## 27 56 Average
## 28 93 Excellent
## 29 89 Excellent
## 30 88 Excellent
## 31 73 Very Good
## 32 43 Poor
## 33 52 Average
## 34 44 Poor
## 35 93 Excellent
## 36 90 Excellent
## 37 64 Good
## 38 91 Excellent
## 39 61 Good
## 40 64 Good
## 41 71 Very Good
## 42 85 Excellent
## 43 64 Good
## 44 62 Good
## 45 74 Very Good
## 46 79 Very Good
## 47 87 Excellent
## 48 69 Good
## 49 51 Average
## 50 70 Good
5 Multi-Company Dataset Simulation
## company employee salary performance KPI
## 1 1 1 9264 62 59
## 2 2 1 4133 68 62
## 3 3 1 6229 96 92
## 4 1 2 8183 88 60
## 5 2 2 8602 53 74
## 6 3 2 4933 50 75
6 Monte Carlo Simulation: Pi & Probability
## [1] 3.1804
7 Advanced Data Transformation & Feature Engineering
## company employee salary performance KPI salary_norm
## 1 1 1 9264 62 59 0.8971387
## 2 2 1 4133 68 62 0.1442406
## 3 3 1 6229 96 92 0.4517975
## 4 1 2 8183 88 60 0.7385180
## 5 2 2 8602 53 74 0.8000000
## 6 3 2 4933 50 75 0.2616288
8 Mini Project: Company KPI Dashboard & Simulation
## company salary KPI
## 1 1 7025.85 72.85
## 2 2 6110.85 71.35
## 3 3 6848.50 75.50
##
## ==============================
## Company: 1
## ==============================
##
## Summary Data:
## company employee salary performance KPI
## Min. :1 Min. : 1.00 Min. :3150 Min. :55.00 Min. :50.00
## 1st Qu.:1 1st Qu.: 5.75 1st Qu.:5230 1st Qu.:61.50 1st Qu.:59.75
## Median :1 Median :10.50 Median :7464 Median :73.00 Median :73.50
## Mean :1 Mean :10.50 Mean :7026 Mean :74.20 Mean :72.85
## 3rd Qu.:1 3rd Qu.:15.25 3rd Qu.:9069 3rd Qu.:85.75 3rd Qu.:82.50
## Max. :1 Max. :20.00 Max. :9965 Max. :98.00 Max. :98.00
## salary_norm
## Min. :0.0000
## 1st Qu.:0.3052
## Median :0.6329
## Mean :0.5687
## 3rd Qu.:0.8685
## Max. :1.0000
##
## Average Salary & KPI:
## company salary KPI
## 1 1 7025.85 72.85
##
## ==============================
## Company: 2
## ==============================
##
## Summary Data:
## company employee salary performance KPI
## Min. :2 Min. : 1.00 Min. :3982 Min. :52.00 Min. :51.00
## 1st Qu.:2 1st Qu.: 5.75 1st Qu.:4322 1st Qu.:58.75 1st Qu.:61.00
## Median :2 Median :10.50 Median :5606 Median :71.00 Median :74.00
## Mean :2 Mean :10.50 Mean :6111 Mean :72.55 Mean :71.35
## 3rd Qu.:2 3rd Qu.:15.25 3rd Qu.:7573 3rd Qu.:86.00 3rd Qu.:80.00
## Max. :2 Max. :20.00 Max. :9809 Max. :97.00 Max. :94.00
## salary_norm
## Min. :0.1221
## 1st Qu.:0.1720
## Median :0.3605
## Mean :0.4345
## 3rd Qu.:0.6490
## Max. :0.9771
##
## Average Salary & KPI:
## company salary KPI
## 1 2 6110.85 71.35
##
## ==============================
## Company: 3
## ==============================
##
## Summary Data:
## company employee salary performance KPI
## Min. :3 Min. : 1.00 Min. :3325 Min. : 50.00 Min. :53.0
## 1st Qu.:3 1st Qu.: 5.75 1st Qu.:4950 1st Qu.: 69.00 1st Qu.:68.5
## Median :3 Median :10.50 Median :6937 Median : 75.50 Median :74.5
## Mean :3 Mean :10.50 Mean :6848 Mean : 77.60 Mean :75.5
## 3rd Qu.:3 3rd Qu.:15.25 3rd Qu.:9081 3rd Qu.: 93.25 3rd Qu.:90.0
## Max. :3 Max. :20.00 Max. :9869 Max. :100.00 Max. :99.0
## salary_norm
## Min. :0.02568
## 1st Qu.:0.26405
## Median :0.55569
## Mean :0.54270
## 3rd Qu.:0.87032
## Max. :0.98591
##
## Average Salary & KPI:
## company salary KPI
## 1 3 6848.5 75.5