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:
- Console: Located on the left-hand side, this is where you’ll input your R code and see the results.
- Global Environment: Stores all your variables and their values.
- Tabs: On the right side, there are various tabs for managing your environment, packages, plots, and files.
Creating Your First R Script
- Go to File > New File > R Script to open a new script window.
- Write your code in the script window.
- To run a line of code, highlight it and press Ctrl + Enter (Windows) or Cmd + Enter (Mac).
- 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+2assigns the value 4 to the variable x).
Saving and Running Your Script
- Save your script by going to File > Save or File > Save As and give it a name with the .R extension.
- 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).
To learn more about R programming and expand your skills, consider these books:
- Machine Learning with R
- Extending Power BI with Python and R: Ingest, transform, enrich, and visualize data using the power of analytical languages
- 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!