Shadow

Data Science

Creating Excel Workbooks with multiple sheets in R

Creating Excel Workbooks with multiple sheets in R

Data Science, Recent Posts
Creating Excel Workbooks Generally, when doing anything in R I typically work with .csv files, their fast and straightforward to use. However, I find times, where I need to create a bunch of them to output and having to go and open each one individually, can be a pain for anyone. In this case, it's much better to create a workbook where each of the .csv files you would have created will now be a separate sheet. Below is a simple script I use frequently that gets the job done. Also included is the initial process of creating dummy data to outline the process. EXAMPLE CODE: Libraries used library(tidyverse) library(openxlsx) Creating example files to work with products <- c("Monitor", "Laptop", "Keyboards", "Mice") Stock <- c(20,10,25,50) Computer_Supplies <- ...
Exploring Employee Attrition and Performance with R

Exploring Employee Attrition and Performance with R

Data Science
Based on IBM's fictional data set created by their data scientists. Introduction: Employee Attrition is when an employee leaves a company due to normal means, (loss of customers, retirement, and resignation), and there is not someone to fill the vacancy. Can a company identify employee’s that are likely to leave a company? A company with a high employee attrition rate is a good sign of underlying problems and can affect a company in a very negative way. One such way is the cost related to finding and training a replacement, as well as the possible strain it can put on other workers that in the meantime have to cover. Preprocessing: This dataset was produced by IBM and has just under 1500 observations of 31 different variables including attrition. 4 of the variables (EmployeeNumber, Over18...
Introduction to Data Analysis with R

Introduction to Data Analysis with R

Data Science, Recent Posts
Using Basic Data Analysis functions on the mtcars dataset Let's Start # Copying mtcars data frame to our new data frame myCarsmyCars <- mtcars Which car has the highest horsepower (hp) ?  #find and display the car with the highest horsepower index <- which.max(myCars$hp)# Display the car name along with the rest of the row myCars[index,] ##                mpg cyl disp hp drat  wt  qsec vs am  gear carb ## Maserati Bora  15   8  301 335 3.54 3.57 14.6  0  1    5    8 Maserati Bora has the highest horsepower at 335 Exploring miles per gallon (mpg) of the cars # find and display the car with the highest mpgind...
Manipulating Data Frames in R

Manipulating Data Frames in R

Data Science, Recent Posts
Learn To Manipulate Data Frames Using The “mtcars” Dataset Below is an introduction to programming with r, all code in this exercise is only using base r and no other libraries are needed. Task 1: Create a new column to find Displacement per Cylinder  Create a new variable (DisplacementPerCylinder), to calculate the total displacement per cylinder in cubic inches for each vehicle from the mtcars dataset. # "str" allows you to display the internal structure of an R object str(mtcars) ## 'data.frame': 32 obs. of 11 variables: ## $ mpg : num 21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ... ## $ cyl : num 6 6 4 6 8 6 8 4 4 6 ... ## $ disp: num 160 160 108 258 360 ... ## $ hp : num 110 110 93 110 175 105 245 62 95 123 ... ## $ drat: num 3.9 3.9 3.85 3.08 3...