📊

Getting Started with R Studio

Aug 6, 2024

HR Analytics 101: Introduction to R Studio

Overview

  • Practical beginners tour of the four panels in R Studio.
  • Focus on analytics.

Opening R Studio

  • Click on R Studio icon in taskbar.
  • If not visible, search for "R Studio" in the search bar.

Four Panels in R Studio

  1. Source Panel (Upper Left)

    • Write and save code scripts in a text file format.
    • Saved scripts allow recreation of analyses.
  2. Console Panel (Lower Left)

    • Displays results of code from the source panel.
    • Allows direct execution of R code interactively.
    • Useful for checking results and data interaction.
  3. Environment Panel (Upper Right)

    • Shows available variables in the current session.
  4. Lower Right Panel

    • Contains tabs for Help, Packages, Plots, etc.
    • If source panel is absent, create a new script via File > New File > R Script.

Working with Panels

  • Spend most time in Source and Console panels.

Example: Creating Variables

  1. Create a new script file.

    • Assign variable x to values 1 through 100.
    • Create variable y as the cumulative sum of x using cumsum function.
  2. Saving Scripts

    • Save using File > Save or Ctrl + S.
  3. Running Code

    • Highlight code and select Run Selected Lines or use Ctrl + Enter.
    • Results appear in Console panel.
    • Use head(y) to view the first six elements of y.
    • Create new variable z as the median of y in the Console.

Environment Panel Details

  • Shows variables created, including z variable.
  • Clear environment using the broom icon.
  • Recreate variables by running the script again.

Lower Right Panel: Tabs Overview

  1. Plots Tab

    • Displays results of plots created in the Source or Console panels.
    • Use arrow to navigate through previous plots.
    • Clear plots using the broom icon.
  2. Help Tab

    • Access help for functions by typing ?function_name in the Console.
    • Example: ?print for help on the print function.
  3. Packages Tab

    • Install new packages (e.g., psyc) through the install button.

Summary

  • Four key panels in R Studio: Source, Console, Environment, and Lower Right.
  • Use Source for scripting and Console for interactive analysis.
  • Environment displays variable information, while Lower Right shows plots, packages, and help files.

Conclusion

  • Overview of R Studio to prepare students for further tutorials at hranalytics101.com.
  • Encouragement to explore additional resources.