Introduction to R Programming: A Beginner’s Guide to RStudio and R Scripts

Hello, my name is Mark Gingrass. In this tutorial, I assume you’ve already installed R and RStudio. This series of tutorials will cater to those with some programming experience, so I will go slightly faster than if you’ve never programmed before. However, you don’t need prior programming experience to follow along; some math knowledge or logic will suffice.

As always, the video tutorial is at the bottom of this blog.

RStudio Interface Overview

After installing the software and opening RStudio, you’ll see the following:

  1. Console: Located on the left-hand side, this is where you’ll input your R code and see the results.
  2. Global Environment: Stores all your variables and their values.
  3. Tabs: On the right side, there are various tabs for managing your environment, packages, plots, and files.

Creating Your First R Script

  1. Go to File > New File > R Script to open a new script window.
  2. Write your code in the script window.
  3. To run a line of code, highlight it and press Ctrl + Enter (Windows) or Cmd + Enter (Mac).
  4. Comments can be added using the hashtag symbol (#) before the text.

Basic Calculations and Assigning Variables

  • Basic calculations can be done in the console, such as 2+4, which returns 6.
  • Complex math operations, exponents, and trig functions are also possible.
  • To assign a value to a variable, use the “<-” notation (e.g., x <- 2+2 assigns the value 4 to the variable x).

Saving and Running Your Script

  1. Save your script by going to File > Save or File > Save As and give it a name with the .R extension.
  2. To run your entire script or specific lines of code, highlight the desired code and press the Run button or Ctrl + Enter (Windows) or Cmd + Enter (Mac).

Recommended Resources

To learn more about R programming and expand your skills, consider these books:

  1. Machine Learning with R
  2. Extending Power BI with Python and R: Ingest, transform, enrich, and visualize data using the power of analytical languages
  3. The Book of R – A First Course in Programming and Statistics

Feel free to leave a comment if you have any questions, and stay tuned for more R programming and data analysis tutorials. Don’t forget to subscribe to help grow the channel and continue creating videos like this. Happy coding!

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *