Chapter 12 Setting A Working Directory | R For HR: An Introduction To ...

  • R for HR
  • Preface
    • 0.1 Growth of HR Analytics
    • 0.2 Skills Gap
    • 0.3 Project Life Cycle Perspective
    • 0.4 Overview of HRIS & HR Analytics
    • 0.5 My Philosophy for This Book
      • 0.5.1 Rationale for Using R
      • 0.5.2 Audience
    • 0.6 Structure
    • 0.7 About the Author
    • 0.8 Contacting the Author
    • 0.9 Acknowledgements
  • I HR Analytics Project Life Cycle
  • 1 Overview of HR Analytics Project Life Cycle
  • 2 Question Formulation
    • 2.1 Adopting a Strategic Mindset
      • 2.1.1 Strategy
      • 2.1.2 Strategy Formulation
      • 2.1.3 Strategy Implementation
      • 2.1.4 Strategic Human Resource Management
    • 2.2 Defining Problems & Formulating Questions
      • 2.2.1 Defining a Problem
      • 2.2.2 Formulating a Question
      • 2.2.3 Thinking Divergently & Convergently
    • 2.3 Summary
  • 3 Data Acquisition
    • 3.1 Employee Surveys
    • 3.2 Rating Forms
    • 3.3 Surveillance & Monitoring
    • 3.4 Database Queries
    • 3.5 Scraping
    • 3.6 Summary
  • 4 Data Management
    • 4.1 Data Cleaning
    • 4.2 Data Manipulation & Structuring
    • 4.3 Common Data-Management Tools
    • 4.4 Summary
  • 5 Data Analysis
    • 5.1 Tools & Techniques
      • 5.1.1 Mathematics
      • 5.1.2 Statistics
      • 5.1.3 Machine Learning
      • 5.1.4 Computational Modeling & Simulations
      • 5.1.5 Text Analyses & Qualitative Analyses
    • 5.2 Continuum of Data Analytics
      • 5.2.1 Descriptive Analytics
      • 5.2.2 Predict-ish Analytics
      • 5.2.3 Predictive Analytics
      • 5.2.4 Prescriptive Analytics
    • 5.3 Summary
  • 6 Data Interpretation & Storytelling
    • 6.1 Data Interpretation
    • 6.2 Storytelling
      • 6.2.1 Structure
      • 6.2.2 Clarity & Parsimony
      • 6.2.3 Influence & Persuasion
    • 6.3 Data Visualization
    • 6.4 Summary
  • 7 Deployment & Implementation
  • II Introduction to R
  • 8 Overview of R & RStudio
    • 8.1 R Programming Language
      • 8.1.1 What Is R?
      • 8.1.2 Why Use R?
      • 8.1.3 Who Uses R?
    • 8.2 RStudio
      • 8.2.1 What is RStudio?
      • 8.2.2 Why RStudio?
      • 8.2.3 Who Uses RStudio?
    • 8.3 Packages
    • 8.4 Summary
  • 9 Installing R & RStudio
    • 9.1 Video Tutorial
    • 9.2 Downloading & Installing R
      • 9.2.1 For Windows Operation Systems
      • 9.2.2 For Mac Operating Systems
    • 9.3 Downloading & Installing RStudio
    • 9.4 Summary
  • 10 Getting Started with R & RStudio
    • 10.1 Orientation to RStudio
    • 10.2 Creating & Saving an R Script
      • 10.2.1 Creating a New R Script
      • 10.2.2 Using an R Script
      • 10.2.3 Saving an R Script
      • 10.2.4 Opening a Saved R Script
    • 10.3 Creating an RStudio Project
      • 10.3.1 Creating a New RStudio Project
      • 10.3.2 Opening an Existing RStudio Project
    • 10.4 Orientation to Written Tutorials
    • 10.5 Summary
  • 11 Basic Features and Operations of the R Language
    • 11.1 Video Tutorial
    • 11.2 Functions & Packages Introduced
    • 11.3 R as a Calculator
    • 11.4 Functions
    • 11.5 Packages
    • 11.6 Variable Assignment
    • 11.7 Types of Data
      • 11.7.1 numeric Data
      • 11.7.2 character Data
      • 11.7.3 Date Data
      • 11.7.4 logical Data
    • 11.8 Vectors
    • 11.9 Lists
    • 11.10 Data Frames
    • 11.11 Annotations
    • 11.12 Summary
  • 12 Setting a Working Directory
    • 12.1 Video Tutorial
    • 12.2 Functions & Packages Introduced
    • 12.3 Identify the Current Working Directory
    • 12.4 Set a New Working Directory
    • 12.5 Summary
  • III Data Acquisition & Management
  • 13 Reading Data into R
    • 13.1 Conceptual Overview
    • 13.2 Tutorial
      • 13.2.1 Video Tutorial
      • 13.2.2 Functions & Packages Introduced
      • 13.2.3 Initial Steps
      • 13.2.4 Read a .csv File
      • 13.2.5 Read a .xlsx File
      • 13.2.6 Summary
    • 13.3 Chapter Supplement
      • 13.3.1 Functions & Packages Introduced
      • 13.3.2 Initial Steps
      • 13.3.3 Additional Functions for Reading a .csv File
      • 13.3.4 Skip Rows of Data During Read
      • 13.3.5 List Data File Names in Working Directory
  • 14 Removing, Adding, & Changing Variable Names
    • 14.1 Conceptual Overview
    • 14.2 Tutorial
      • 14.2.1 Video Tutorial
      • 14.2.2 Functions & Packages Introduced
      • 14.2.3 Initial Steps
      • 14.2.4 Remove Variable Names from a Data Frame Object
      • 14.2.5 Add Variable Names to a Data Frame Object
      • 14.2.6 Change Specific Variable Names in a Data Frame Object
      • 14.2.7 Summary
  • 15 Writing Data from R
    • 15.1 Conceptual Overview
    • 15.2 Tutorial
      • 15.2.1 Video Tutorial
      • 15.2.2 Functions & Packages Introduced
      • 15.2.3 Initial Steps
      • 15.2.4 Write Data Frame to Working Directory
      • 15.2.5 Write Table to Working Directory
      • 15.2.6 Summary
  • 16 Arranging (Sorting) Data
    • 16.1 Conceptual Overview
    • 16.2 Tutorial
      • 16.2.1 Video Tutorial
      • 16.2.2 Functions & Packages Introduced
      • 16.2.3 Initial Steps
      • 16.2.4 Arrange (Sort) Data
      • 16.2.5 Summary
    • 16.3 Chapter Supplement
      • 16.3.1 Functions & Packages Introduced
      • 16.3.2 Initial Steps
      • 16.3.3 order Function from Base R
  • 17 Joining (Merging) Data
    • 17.1 Conceptual Overview
      • 17.1.1 Review of Horizontal Joins (Merges)
      • 17.1.2 Review of Vertical Joins (Merges)
    • 17.2 Tutorial
      • 17.2.1 Video Tutorial
      • 17.2.2 Functions & Packages Introduced
      • 17.2.3 Initial Steps
      • 17.2.4 Horizontal Join (Merge)
      • 17.2.5 Vertical Join (Merge)
      • 17.2.6 Summary
    • 17.3 Chapter Supplement
      • 17.3.1 Video Tutorial
      • 17.3.2 Functions & Packages Introduced
      • 17.3.3 Initial Steps
      • 17.3.4 merge Function from Base R
  • 18 Filtering (Subsetting) Data
    • 18.1 Conceptual Overview
      • 18.1.1 Review of Logical Operators
    • 18.2 Tutorial
      • 18.2.1 Video Tutorial
      • 18.2.2 Functions & Packages Introduced
      • 18.2.3 Initial Steps
      • 18.2.4 Filter Cases from Data Frame
      • 18.2.5 Remove Single Variable from Data Frame
      • 18.2.6 Select Multiple Variables from Data Frame
      • 18.2.7 Remove Multiple Variables from Data Frame
      • 18.2.8 Summary
    • 18.3 Chapter Supplement
      • 18.3.1 Video Tutorials
      • 18.3.2 Functions & Packages Introduced
      • 18.3.3 Initial Steps
      • 18.3.4 subset Function from Base R
      • 18.3.5 Filter by Pattern Contained within String
  • 19 Cleaning Data
    • 19.1 Conceptual Overview
    • 19.2 Tutorial
      • 19.2.1 Video Tutorial
      • 19.2.2 Functions & Packages Introduced
      • 19.2.3 Initial Steps
      • 19.2.4 Review Data
      • 19.2.5 Clean Data
      • 19.2.6 Rename Variables
      • 19.2.7 Other Approaches to Cleaning Data
      • 19.2.8 Summary
  • 20 Manipulating & Restructuring Data
    • 20.1 Conceptual Overview
    • 20.2 Tutorial
      • 20.2.1 Video Tutorial
      • 20.2.2 Functions & Packages Introduced
      • 20.2.3 Initial Steps
      • 20.2.4 Wide-to-Long Format Data Manipulation
      • 20.2.5 Long-to-Wide Format Data Manipulation
      • 20.2.6 Summary
  • 21 Centering & Standardizing Variables
    • 21.1 Conceptual Overview
      • 21.1.1 Review of Centering Variables
      • 21.1.2 Review of Standardizing Variables
    • 21.2 Tutorial
      • 21.2.1 Video Tutorial
      • 21.2.2 Functions & Packages Introduced
      • 21.2.3 Initial Steps
      • 21.2.4 Grand-Mean Center Variables
      • 21.2.5 Group-Mean Center Variables
      • 21.2.6 Standardize Variables
      • 21.2.7 Summary
  • 22 Removing Objects from the R Environment
    • 22.1 Conceptual Overview
    • 22.2 Tutorial
      • 22.2.1 Video Tutorial
      • 22.2.2 Functions & Packages Introduced
      • 22.2.3 Initial Steps
      • 22.2.4 List Objects in R Environment
      • 22.2.5 Remove Objects from R Environment
      • 22.2.6 Summary
  • IV Employee Demographics
  • 23 Introduction to Employee Demographics
    • 23.1 Chapters Included
  • 24 Describing Employee Demographics Using Descriptive Statistics
    • 24.1 Conceptual Overview
      • 24.1.1 Review of Measurement Scales
      • 24.1.2 Constructs, Measures, & Measurement Scales
      • 24.1.3 Types of Descriptive Statistics
      • 24.1.4 Sample Write-Up
    • 24.2 Tutorial
      • 24.2.1 Video Tutorials
      • 24.2.2 Functions & Packages Introduced
      • 24.2.3 Initial Steps
      • 24.2.4 Determine the Measurement Scale
      • 24.2.5 Describe Nominal & Ordinal (Categorical) Variables
      • 24.2.6 Describe Interval & Ratio (Continuous) Variables
      • 24.2.7 Summary
    • 24.3 Chapter Supplement
      • 24.3.1 Functions & Packages Introduced
      • 24.3.2 Initial Steps
      • 24.3.3 Compute Coefficient of Variation (CV)
  • 25 Summarizing Two or More Categorical Variables Using Cross-Tabulations
    • 25.1 Conceptual Overview
      • 25.1.1 Review of Cross-Tabulation
      • 25.1.2 Sample Write-Up
    • 25.2 Tutorial
      • 25.2.1 Video Tutorial
      • 25.2.2 Functions & Packages Introduced
      • 25.2.3 Initial Steps
      • 25.2.4 Two-Way Cross-Tabulation
      • 25.2.5 Three-Way Cross-Tabulation
      • 25.2.6 Summary
  • 26 Applying Pivot Tables to Explore Employee Demographic Data
    • 26.1 Conceptual Overview
    • 26.2 Tutorial
      • 26.2.1 Video Tutorial
      • 26.2.2 Functions & Packages Introduced
      • 26.2.3 Initial Steps
      • 26.2.4 Create a Pivot Table
      • 26.2.5 Summary
  • V Employee Surveys
  • 27 Introduction to Employee Surveys
    • 27.1 Chapters Included
  • 28 Aggregating & Segmenting Employee Survey Data
    • 28.1 Conceptual Overview
    • 28.2 Tutorial
      • 28.2.1 Video Tutorial
      • 28.2.2 Functions & Packages Introduced
      • 28.2.3 Initial Steps
      • 28.2.4 Counts By Group
      • 28.2.5 Measures of Central Tendency and Dispersion By Group
      • 28.2.6 Add Variable to Data Frame Containing Aggregated Values
      • 28.2.7 Visualize Data By Group
      • 28.2.8 Summary
    • 28.3 Chapter Supplement
      • 28.3.1 Functions & Packages Introduced
      • 28.3.2 Initial Steps
      • 28.3.3 describeBy Function from psych Package
      • 28.3.4 aggregate Function from Base R
  • 29 Estimating Internal Consistency Reliability Using Cronbach’s alpha
    • 29.1 Conceptual Overview
    • 29.2 Tutorial
      • 29.2.1 Video Tutorial
      • 29.2.2 Functions & Packages Introduced
      • 29.2.3 Initial Steps
      • 29.2.4 Compute Cronbach’s alpha
      • 29.2.5 Summary
  • 30 Creating a Composite Variable Based on a Multi-Item Measure
    • 30.1 Conceptual Overview
    • 30.2 Tutorial
      • 30.2.1 Video Tutorial
      • 30.2.2 Functions & Packages Introduced
      • 30.2.3 Initial Steps
      • 30.2.4 Compute Cronbach’s alpha
      • 30.2.5 Create a Composite Variable
      • 30.2.6 Summary
  • VI Employee Training
  • 31 Introduction to Employee Training
    • 31.1 Needs Assessment
    • 31.2 Learning Environment & Enhancement
    • 31.3 Training Methods
    • 31.4 Training Evaluation
      • 31.4.1 Causal Inferences
      • 31.4.2 Training Evaluation Designs & Statistical Analysis
    • 31.5 Chapters Included
  • 32 Evaluating a Pre-Test/Post-Test without Control Group Design Using Paired-Samples t-test
    • 32.1 Conceptual Overview
      • 32.1.1 Review of Pre-Test/Post-Test without Control Group Design
      • 32.1.2 Review of Paired-Samples t-test
    • 32.2 Tutorial
      • 32.2.1 Video Tutorial
      • 32.2.2 Functions & Packages Introduced
      • 32.2.3 Initial Steps
      • 32.2.4 Estimate Paired-Samples t-test
      • 32.2.5 Visualize Results Using Bar Chart
      • 32.2.6 Summary
    • 32.3 Chapter Supplement
      • 32.3.1 Functions & Packages Introduced
      • 32.3.2 Initial Steps
      • 32.3.3 t.test Function from Base R
      • 32.3.4 lm Function from Base R
  • 33 Evaluating a Post-Test-Only with Control Group Design Using Independent-Samples t-test
    • 33.1 Conceptual Overview
      • 33.1.1 Review of Post-Test-Only with Control Group Design
      • 33.1.2 Review of Independent-Samples t-test
    • 33.2 Tutorial
      • 33.2.1 Video Tutorial
      • 33.2.2 Functions & Packages Introduced
      • 33.2.3 Initial Steps
      • 33.2.4 Estimate Independent-Samples t-test
      • 33.2.5 Visualize Results Using Bar Chart
      • 33.2.6 Summary
    • 33.3 Chapter Supplement
      • 33.3.1 Functions & Packages Introduced
      • 33.3.2 Initial Steps
      • 33.3.3 t.test Function from Base R
      • 33.3.4 lm Function from Base R
  • 34 Evaluating a Pre-Test/Post-Test with Control Group Design Using an Independent-Samples t-test
    • 34.1 Conceptual Overview
      • 34.1.1 Statistical Assumptions
    • 34.2 Tutorial
      • 34.2.1 Video Tutorial
      • 34.2.2 Functions & Packages Introduced
      • 34.2.3 Initial Steps {#initsteps_mixedfactorial}}
      • 34.2.4 Evaluate a Pre-Test/Post-Test with Control Group Design
      • 34.2.5 Summary
    • 34.3 Chapter Supplement
      • 34.3.1 Functions & Packages Introduced
      • 34.3.2 Initial Steps
      • 34.3.3 Estimating a Simple Linear Regression Model with a Difference Score Outcome Variable
      • 34.3.4 Estimating a Biserial Correlation with a Difference Score Outcome Variable
      • 34.3.5 Estimating a 2x2 Mixed-Factorial ANOVA Model
      • 34.3.6 Estimating a Random-Coefficients Multilevel Model
      • 34.3.7 Estimating an Analysis of Covariance Model
  • 35 Evaluating a Post-Test-Only with Two Comparison Groups Design Using One-Way ANOVA
    • 35.1 Conceptual Overview
      • 35.1.1 Review of Post-Test-Only with Two Comparison Groups Design
      • 35.1.2 Review of One-Way ANOVA
    • 35.2 Tutorial
      • 35.2.1 Video Tutorial
      • 35.2.2 Functions & Packages Introduced
      • 35.2.3 Initial Steps
      • 35.2.4 Test Statistical Assumptions
      • 35.2.5 Estimate One-Way ANOVA
      • 35.2.6 Visualize Results Using Bar Chart
      • 35.2.7 Summary
    • 35.3 Chapter Supplement
      • 35.3.1 Functions & Packages Introduced
      • 35.3.2 Initial Steps
      • 35.3.3 aov Function from Base R
      • 35.3.4 APA-Style Table of Results
  • VII Employee Selection
  • 36 Introduction to Employee Selection
    • 36.1 Evaluating Selection Tools
    • 36.2 Chapters Included
  • 37 Investigating Disparate Impact
    • 37.1 Conceptual Overview
    • 37.2 Tutorial
      • 37.2.1 Video Tutorial
      • 37.2.2 Functions & Packages Introduced
      • 37.2.3 Initial Steps
      • 37.2.4 4/5ths Rule
      • 37.2.5 Chi-Square (\(\chi^2\)) Test of Independence
      • 37.2.6 Fisher Exact Test
      • 37.2.7 \(Z_{D}\) Test
      • 37.2.8 \(Z_{IR}\) Test
      • 37.2.9 Summary
  • 38 Estimating Criterion-Related Validity of a Selection Tool Using Correlation
    • 38.1 Conceptual Overview
      • 38.1.1 Review of Criterion-Related Validity
      • 38.1.2 Review of Correlation
    • 38.2 Tutorial
      • 38.2.1 Video Tutorial
      • 38.2.2 Functions & Packages Introduced
      • 38.2.3 Initial Steps
      • 38.2.4 Visualize Association Using a Scatter Plot
      • 38.2.5 Estimate Correlation
      • 38.2.6 Summary
    • 38.3 Chapter Supplement
      • 38.3.1 Functions & Packages Introduced
      • 38.3.2 Initial Steps
      • 38.3.3 cor Function from Base R
      • 38.3.4 cor.test Function from Base R
  • 39 Predicting Criterion Scores Based on Selection Tool Scores Using Simple Linear Regression
    • 39.1 Conceptual Overview
      • 39.1.1 Review of Simple Linear Regression
      • 39.1.2 Predicting Future Criterion Scores Using Simple Linear Regression
    • 39.2 Tutorial
      • 39.2.1 Video Tutorials
      • 39.2.2 Functions & Packages Introduced
      • 39.2.3 Initial Steps
      • 39.2.4 Estimate Simple Linear Regression Model
      • 39.2.5 Predict Criterion Scores
      • 39.2.6 Summary
    • 39.3 Chapter Supplement
      • 39.3.1 Functions & Packages Introduced
      • 39.3.2 Initial Steps
      • 39.3.3 lm Function from Base R
      • 39.3.4 predict Function from Base R
      • 39.3.5 APA-Style Results Table
  • 40 Estimating Incremental Validity of a Selection Tool Using Multiple Linear Regression
    • 40.1 Conceptual Overview
      • 40.1.1 Review of Multiple Linear Regression
    • 40.2 Tutorial
      • 40.2.1 Video Tutorials
      • 40.2.2 Functions & Packages Introduced
      • 40.2.3 Initial Steps
      • 40.2.4 Estimate Multiple Linear Regression Model
      • 40.2.5 Summary
    • 40.3 Chapter Supplement
      • 40.3.1 Functions & Packages Introduced
      • 40.3.2 Initial Steps
      • 40.3.3 lm Function from Base R
      • 40.3.4 APA-Style Results Table
  • 41 Applying a Compensatory Approach to Selection Decisions Using Multiple Linear Regression
    • 41.1 Conceptual Overview
      • 41.1.1 Review of Multiple Linear Regression
      • 41.1.2 Review of Compensatory Approach
    • 41.2 Tutorial
      • 41.2.1 Video Tutorial
      • 41.2.2 Functions & Packages Introduced
      • 41.2.3 Initial Steps
      • 41.2.4 Estimate Multiple Linear Regression Model
      • 41.2.5 Predict Criterion Scores
      • 41.2.6 Summary
    • 41.3 Chapter Supplement
      • 41.3.1 Functions & Packages Introduced
      • 41.3.2 Initial Steps
      • 41.3.3 lm & predict Functions from Base R
  • 42 Applying a Noncompensatory Approach to Selection Decisions Using Angoff Method
    • 42.1 Conceptual Overview
      • 42.1.1 Review of Noncompensatory Approach
    • 42.2 Tutorial
      • 42.2.1 Video Tutorial
      • 42.2.2 Functions & Packages Introduced
      • 42.2.3 Initial Steps
      • 42.2.4 Create Cutoff Scores
      • 42.2.5 Apply Cutoff Scores to Make Selection Decisions
      • 42.2.6 Summary
  • 43 Testing for Differential Prediction Using Moderated Multiple Linear Regression
    • 43.1 Conceptual Overview
      • 43.1.1 Review of Moderated Multiple Linear Regression
      • 43.1.2 Review of Differential Prediction
    • 43.2 Tutorial
      • 43.2.1 Video Tutorial
      • 43.2.2 Functions & Packages Introduced
      • 43.2.3 Initial Steps
      • 43.2.4 Grand-Mean Center Continuous Predictor Variables
      • 43.2.5 Estimate Moderated Multiple Linear Regression Model
      • 43.2.6 Summary
    • 43.3 Chapter Supplement
      • 43.3.1 Functions & Packages Introduced
      • 43.3.2 Initial Steps
      • 43.3.3 lm Function from Base R
      • 43.3.4 APA-Style Results Table
  • 44 Statistically & Empirically Cross-Validating a Selection Tool
    • 44.1 Conceptual Overview
      • 44.1.1 Review of Statistical Cross-Validation
      • 44.1.2 Review of Empirical Cross-Validation
    • 44.2 Tutorial
      • 44.2.1 Functions & Packages Introduced
      • 44.2.2 Initial Steps
      • 44.2.3 Perform Statistical Cross-Validation
      • 44.2.4 Perform Empirical Cross-Validation
      • 44.2.5 Summary
  • VIII Employee Separation & Retention
  • 45 Introduction to Employee Separation & Retention
    • 45.1 Chapters Included
  • 46 Computing Monthly & Annual Turnover Rates
    • 46.1 Conceptual Overview
    • 46.2 Tutorial
      • 46.2.1 Video Tutorial
      • 46.2.2 Functions & Packages Introduced
      • 46.2.3 Initial Steps
      • 46.2.4 Compute Monthly Turnover Rates
      • 46.2.5 Compute Annual Turnover Rate
      • 46.2.6 Summary
  • 47 Estimating the Association Between Two Categorical Variables Using Chi-Square (\(\chi^2\)) Test of Independence
    • 47.1 Conceptual Overview
    • 47.2 Tutorial
      • 47.2.1 Video Tutorial
      • 47.2.2 Functions & Packages Introduced
      • 47.2.3 Initial Steps
      • 47.2.4 Create a Contingency Table for Observed Data
      • 47.2.5 Estimate Chi-Square (\(\chi^2\)) Test of Independence
      • 47.2.6 Summary
    • 47.3 Chapter Supplement
      • 47.3.1 Functions & Packages Introduced
      • 47.3.2 Initial Steps
      • 47.3.3 Compute Odds Ratio for 2x2 Contingency Table
  • 48 Identifying Predictors of Turnover Using Logistic Regression
    • 48.1 Conceptual Overview
      • 48.1.1 Review of Logistic Regression
    • 48.2 Tutorial
      • 48.2.1 Video Tutorials
      • 48.2.2 Functions & Packages Introduced
      • 48.2.3 Initial Steps
      • 48.2.4 Estimate Simple Logistic Regression Model
      • 48.2.5 Estimate Multiple Logistic Regression Model
      • 48.2.6 Summary
    • 48.3 Chapter Supplement
      • 48.3.1 Functions & Packages Introduced
      • 48.3.2 Initial Steps
      • 48.3.3 Simple Logistic Regression Model Using glm Function from Base R
      • 48.3.4 Multiple Logistic Regression Using glm Function from Base R
  • 49 Applying k-Fold Cross-Validation to Logistic Regression
    • 49.1 Conceptual Overview
      • 49.1.1 Review of Predictive Analytics
      • 49.1.2 Review of k-Fold Cross-Validation
      • 49.1.3 Conceptual Video
    • 49.2 Tutorial
      • 49.2.1 Video Tutorials
      • 49.2.2 Functions & Packages Introduced
      • 49.2.3 Initial Steps
      • 49.2.4 Apply k-Fold Cross-Validation Using Logistic Regression
      • 49.2.5 Summary
  • 50 Understanding Length of Service Using Survival Analysis
    • 50.1 Conceptual Overview
      • 50.1.1 Censoring
      • 50.1.2 Types of Survival Analysis
      • 50.1.3 Conceptual Video
    • 50.2 Tutorial
      • 50.2.1 Video Tutorials
      • 50.2.2 Functions & Packages Introduced
      • 50.2.3 Initial Steps
      • 50.2.4 Create a Censoring Variable
      • 50.2.5 Inspect Distribution of Length of Service
      • 50.2.6 Conduct Kaplan-Meier Analysis & Create Life Table
      • 50.2.7 Estimate Cox Proportional Hazards Model
      • 50.2.8 Summary
  • IX Employee Performance Management
  • 51 Introduction to Employee Performance Management
    • 51.1 Chapters Included
  • 52 Evaluating Convergent & Discriminant Validity Using Scatter Plots & Correlations
    • 52.1 Conceptual Overview
      • 52.1.1 Review of Concurrent & Discriminant Validity
      • 52.1.2 Review of Pearson Product-Moment & Point-Biserial Correlation
      • 52.1.3 Review of Bivariate Scatter Plot
    • 52.2 Tutorial
      • 52.2.1 Video Tutorial
      • 52.2.2 Functions & Packages Introduced
      • 52.2.3 Initial Steps
      • 52.2.4 Visualize Association Using a Bivariate Scatter Plot
      • 52.2.5 Estimate Correlations
      • 52.2.6 Create Correlation Matrix
      • 52.2.7 Summary
    • 52.3 Chapter Supplement
      • 52.3.1 Functions & Packages Introduced
      • 52.3.2 Initial Steps
      • 52.3.3 shapiro.test Function from Base R
      • 52.3.4 APA-Style Results Table
      • 52.3.5 cor.plot Function from psych package
      • 52.3.6 corrgram Function from corrgram package
  • 53 Investigating Nonlinear Associations Using Polynomial Regression
    • 53.1 Conceptual Overview
      • 53.1.1 Statistical Assumptions
      • 53.1.2 Statistical Significance
    • 53.2 Tutorial
      • 53.2.1 Functions & Packages Introduced
      • 53.2.2 Initial Steps
      • 53.2.3 Visualize Association Using a Bivariate Scatter Plot
      • 53.2.4 Estimate Polynomial Regression Model
      • 53.2.5 Summary
  • 54 Supervised Statistical Learning Using Lasso Regression
    • 54.1 Conceptual Overview
      • 54.1.1 Shrinkage
      • 54.1.2 Regularization
      • 54.1.3 Tuning
      • 54.1.4 Model Type Selection
      • 54.1.5 Cross-Validation
      • 54.1.6 Predictive Analytics
      • 54.1.7 Conceptual Video
    • 54.2 Tutorial
      • 54.2.1 Video Tutorials
      • 54.2.2 Functions & Packages Introduced
      • 54.2.3 Initial Steps
      • 54.2.4 Process Overview
      • 54.2.5 Partition the Data
      • 54.2.6 Specify k-Fold Cross-Validation
      • 54.2.7 Specify and Train Lasso Regression Model
      • 54.2.8 Optional: Compare to Lasso Model to OLS Multiple Linear Regression Model
      • 54.2.9 Summary
  • 55 Investigating Processes Using Path Analysis
    • 55.1 Conceptual Overview
      • 55.1.1 Path Diagram
      • 55.1.2 Model Identification
      • 55.1.3 Model Fit
      • 55.1.4 Parameter Estimates
      • 55.1.5 Statistical Assumptions
      • 55.1.6 Conceptual Video
    • 55.2 Tutorial
      • 55.2.1 Video Tutorial
      • 55.2.2 Functions & Packages Introduced
      • 55.2.3 Initial Steps
      • 55.2.4 Specifying & Estimating Path Analysis Models
      • 55.2.5 Obtaining Standardized Parameter Estimates
      • 55.2.6 Alternative Approaches to Model Specifications
      • 55.2.7 Estimating Models with Missing Data
      • 55.2.8 Summary
  • 56 Estimating a Mediation Model Using Path Analysis
    • 56.1 Conceptual Overview
      • 56.1.1 Estimation of Indirect Effect
      • 56.1.2 Model Identification
      • 56.1.3 Model Fit
      • 56.1.4 Parameter Estimates
      • 56.1.5 Statistical Assumptions
      • 56.1.6 Conceptual Video
    • 56.2 Tutorial
      • 56.2.1 Video Tutorial
      • 56.2.2 Functions & Packages Introduced
      • 56.2.3 Initial Steps
      • 56.2.4 Specifying & Estimating a Mediation Analysis Model
      • 56.2.5 Obtaining Standardized Parameter Estimates
      • 56.2.6 Estimating Models with Missing Data
      • 56.2.7 Summary
  • 57 Evaluating Measurement Models Using Confirmatory Factor Analysis
    • 57.1 Conceptual Overview
      • 57.1.1 Path Diagrams
      • 57.1.2 Model Identification
      • 57.1.3 Model Fit
      • 57.1.4 Parameter Estimates
      • 57.1.5 Model Comparisons
      • 57.1.6 Statistical Assumptions
    • 57.2 Tutorial
      • 57.2.1 Video Tutorial
      • 57.2.2 Functions & Packages Introduced
      • 57.2.3 Initial Steps
      • 57.2.4 Estimate One-Factor CFA Models
      • 57.2.5 Estimate Multi-Factor CFA Models
      • 57.2.6 Nested Model Comparisons
      • 57.2.7 Estimate Second-Order Model
      • 57.2.8 Estimating Models with Missing Data
      • 57.2.9 Simulate Dynamic Fit Index Cutoffs
      • 57.2.10 Summary
  • 58 Estimating Structural Regression Models Using Structural Equation Modeling
    • 58.1 Conceptual Overview
      • 58.1.1 Path Diagrams
      • 58.1.2 Model Identification
      • 58.1.3 Model Fit
      • 58.1.4 Parameter Estimates
      • 58.1.5 Model Comparisons
      • 58.1.6 Statistical Assumptions
    • 58.2 Tutorial
      • 58.2.1 Video Tutorial
      • 58.2.2 Functions & Packages Introduced
      • 58.2.3 Initial Steps
      • 58.2.4 Evaluate the Measurement Model Using Confirmatory Factor Analysis
      • 58.2.5 Estimate a Structural Regression Model
      • 58.2.6 Nested Model Comparisons
      • 58.2.7 Estimating Indirect Effects in Mediation Models
      • 58.2.8 Estimating Models with Missing Data
      • 58.2.9 Summary
  • 59 Estimating Change Using Latent Growth Modeling
    • 59.1 Conceptual Overview
      • 59.1.1 Path Diagrams
      • 59.1.2 Model Identification
      • 59.1.3 Model Fit
      • 59.1.4 Parameter Estimates
      • 59.1.5 Model Comparisons
      • 59.1.6 Statistical Assumptions
    • 59.2 Tutorial
      • 59.2.1 Video Tutorial
      • 59.2.2 Functions & Packages Introduced
      • 59.2.3 Initial Steps
      • 59.2.4 Visualizing Change
      • 59.2.5 Estimate Unconditional Unconstrained Latent Growth Model
      • 59.2.6 Nested Model Comparisons
      • 59.2.7 Estimate Nonlinear Latent Growth Models
      • 59.2.8 Estimating Models with Missing Data
      • 59.2.9 Summary
  • X Employee Compensation & Reward Systems
  • 60 Introduction to Employee Compensation & Reward Systems
    • 60.1 Chapters Included
  • 61 Preparing Market Survey Data
    • 61.1 Conceptual Overview
      • 61.1.1 Aging Market Survey Data
      • 61.1.2 Applying Market Survey Weights
      • 61.1.3 Conceptual Video
    • 61.2 Tutorial
      • 61.2.1 Video Tutorials
      • 61.2.2 Functions & Packages Introduced
      • 61.2.3 Initial Steps
      • 61.2.4 Age the Data
      • 61.2.5 Compute the Sample-Weighted Means
      • 61.2.6 Summary
  • 62 Estimating a Market Pay Line Using Linear & Polynomial Regression
    • 62.1 Conceptual Overview
      • 62.1.1 Statistical Assumptions
      • 62.1.2 Statistical Significance
      • 62.1.3 Practical Significance
      • 62.1.4 Conceptual Video
    • 62.2 Tutorial
      • 62.2.1 Video Tutorial
      • 62.2.2 Functions & Packages Introduced
      • 62.2.3 Initial Steps
      • 62.2.4 Estimate a Market Pay Line
      • 62.2.5 Summary
  • 63 Identifying Pay Determinants & Evaluating Pay Equity Using Hierarchical Linear Regression
    • 63.1 Conceptual Overview
      • 63.1.1 Review of Hiearchical Linear Regression
      • 63.1.2 Conceptual Videos
    • 63.2 Tutorial
      • 63.2.1 Video Tutorial
      • 63.2.2 Functions & Packages Introduced
      • 63.2.3 Initial Steps
      • 63.2.4 Perform Hierarchical Linear Regression
      • 63.2.5 Summary
  • 64 Computing Compa-Ratios & Investigating Pay Compression
    • 64.1 Conceptual Overview
      • 64.1.1 Conceptual Videos
    • 64.2 Tutorial
      • 64.2.1 Video Tutorial
      • 64.2.2 Functions & Packages Introduced
      • 64.2.3 Initial Steps
      • 64.2.4 Compute Compa-Ratio for Each Employee
      • 64.2.5 Compute Compa-Ratio for Group of Employees
      • 64.2.6 Investigate Pay Compression and Pay Inversion
      • 64.2.7 Summary
  • XI Odds & Ends
  • 65 Primer on Data
  • 66 Legal & Ethical Issues
  • 67 Judgment, Decision Making, & Bias
  • 68 Language Considerations
  • 69 Creating a Data Analytics Portfolio
  • 70 Careers in Human Resource Analytics
  • 71 Conducting a Literature Search & Review
  • 72 Statistical & Practical Significance
  • 73 Missing Data
  • 74 Power Analysis
  • References
  • Published with bookdown
R for HR: An Introduction to Human Resource Analytics Using R Chapter 12 Setting a Working Directory

A working directory refers to the location of a folder within a hierarchical file system. For our purposes, a working directory contains data files associated with a particular task or project. Ideally, a single working directory contains all of the data files you need for a task or project, but in some instances, it might make sense to have multiple working directories for a single project. From our designated working directory, we can read in data files (i.e., import files) to the R environment without adding long paths as prefixes in front of the variable names. Further, anytime you save a plot, data frame, or other object created in R, the default will be to save it to the folder you have set as your working directory (i.e., export files).

12.1 Video Tutorial

As usual, you have the choice to follow along with the written tutorial in this chapter or to watch the video tutorial below. Both versions of the tutorial demonstrate how to identify what your current working directory is and how to set a new working directory.

Link to video tutorial: https://youtu.be/oSqOqvMkhSE

12.2 Functions & Packages Introduced

Function Package
getwd base R
setwd base R

12.3 Identify the Current Working Directory

To determine if a working directory has already been set, and if so, what that working directory is, use the getwd (get working directory) function from base R. Because this function comes standard with our R download, we don’t need to install an additional package to access it. For this function, you don’t need any arguments within the parentheses; in other words, leave the function parentheses empty. Alternatively, if you are using RStudio, you will see your current working directory next to the word “Console” in your Console window.

# Find your current working directory getwd()

12.4 Set a New Working Directory

Let’s assume that the current working directory is not what we want; meaning, we need to set a new or different working directory. If you need to set a new working directory, you can use the setwd function from base R. Within the parentheses, your only argument will be the working directory in quotation marks. I recommend typing your setwd function into an R Script (.R) file so that it can be saved for future sessions. I also recommend using the # to annotate your script so that you can remind yourself (and others) what you are doing.

When it comes to working directories, R likes the forward slash (/) (as opposed to backslash). Remember, the working directory is the location of the data files you wish to access and bring into the R environment. You can access any folder you would like and set it as your working directory. For example, in the code below, I set my working directory to H:/RWorkshop, as that folder at the end of that path contains the data files I would like to work with. The folder (and associated path) you set as your working directory will almost certainly be different than the one I set below.

# Set your working directory setwd("H:/RWorkshop")

Alternatively, you may use the drop-down menus to select a working directory folder. To do so, go to Session > Set Working Directory > Choose Directory…, and select the folder where your files live. Upon doing so, your working directory will appear in the Console. You can copy and paste the working directory into your setwd function.

Once you have set your working directory, you can verify that it was set to the correct folder by (a) typing getwd() into your console or (b) looking at the working directory listed next to the word “Console” in your Console window.

12.5 Summary

In this chapter, you learned how to get and set a working directory using the getwd and setwd functions from base R.

Tag » How To Set Working Directory In R