In this section, you will learn the fundamentals of R and RStudio, which are among the most powerful tools for statistical computing, data analysis, machine learning, and data visualization. By the end of this section, you will be familiar with the R programming environment, understand the purpose of RStudio, and be able to perform basic operations within the R console.
After completing this section, you will be able to:
At the end of this section, you will be able to:
Upon successful completion of this section, you will have a solid understanding of the R programming environment and RStudio interface. You will be prepared to write, execute, and manage R scripts efficiently, providing a strong foundation for the advanced topics covered in subsequent sections of the course, including data manipulation, visualization, statistical analysis, and machine learning.
R is a free, open-source programming language and software environment designed for statistical computing, data analysis, machine learning, and graphical visualization. It was developed by Ross Ihaka and Robert Gentleman at the University of Auckland, New Zealand, and has become one of the most widely used programming languages in academia, research, healthcare, finance, business analytics, and artificial intelligence.
R provides thousands of built-in functions and more than 20,000 packages contributed by the global R community through the Comprehensive R Archive Network (CRAN). These packages extend R’s capabilities to perform advanced statistical analyses, create publication-quality graphics, develop predictive models, and analyze large datasets.
Today, R is widely used by:
R has become one of the most important programming languages for data analysis because it combines statistical power with flexibility.
R is used in almost every field involving data.
RStudio is an Integrated Development Environment (IDE) for R.
Think of R as the engine, while RStudio is the dashboard that makes using R easier and more efficient.
RStudio provides a user-friendly interface that helps you write, organize, run, debug, and manage R code.
Instead of using the basic R console, most professionals use RStudio because it offers:
Visit the official CRAN website:
Choose your operating system:
Download the latest stable version.
Run the installer using the default settings.
Download RStudio Desktop from:
https://posit.co/download/rstudio-desktop/
Install RStudio after installing R.
Important: R must be installed before RStudio.
When you open RStudio, you will see four main panels.
Used to write and save R scripts.
Example:
x <- 10
y <- 20
x + yThe Console executes R commands immediately.
Example:
5 + 10Output:
15Displays all variables, datasets, functions, and objects currently loaded into memory.
Example:
x = 10
y = 20Browse folders.
Display graphs.
Install and load packages.
Access documentation.
Display HTML content and interactive applications.
Click:
File → New File → R Script
Write:
print("Hello, World!")Save the file as:
Lesson1.RRun one line:
Ctrl + Enter
Run the entire script:
Ctrl + Shift + Enter
Addition
5 + 6Subtraction
20 - 4Multiplication
5 * 7Division
20 / 4Exponent
5^2Square Root
sqrt(25)Variables store data for later use.
Example:
age <- 25
height <- 170
weight <- 70Display a variable:
ageOutput:
25Comments help explain your code and are ignored during execution.
# This is a comment
x <- 100Packages extend R’s functionality.
Install a package:
install.packages("ggplot2")Load the package:
library(ggplot2)Use:
?meanor
help(mean)Search documentation:
??regressionCheck the current working directory:
getwd()Set a working directory:
setwd("C:/Users/YourName/Documents/RProject")Creating an R Project keeps your scripts, data, outputs, and results organized.
To create a new project:
Using projects helps avoid issues with file paths and improves reproducibility.
WhatsApp us