Data Analytics with R – R is a powerful statistical programming language widely used in data analysis, machine learning, and visualization. This guide will walk you through the basics, from setting up R to executing scripts and creating visualizations.

Data Analytics with R
1. Exploring Basic Features of R – Data Analytics with R
What is R?
R is an open-source language designed for statistical computing and graphics. It is widely used in academia, research, and industry for analyzing and visualizing data.
Key Features of R:
- Open-source and available for free.
- Supports statistical analysis, data manipulation, and visualization.
- A vast collection of libraries for various applications (e.g.,
ggplot2
for visualization,dplyr
for data manipulation). - Integration with other programming languages like Python, C, and SQL.
- Strong community support with thousands of packages on CRAN (Comprehensive R Archive Network).
Installing R and RStudio
- Download R from the official CRAN website: https://cran.r-project.org/.
- Install RStudio, an IDE for R, from https://posit.co/download/rstudio-desktop/.
- Open RStudio and start coding in R.
2. Exploring RGUI (R Graphical User Interface)
R comes with a built-in GUI called RGUI. It allows you to write and execute R commands in an interactive environment.
Features of RGUI:
- Console: Executes commands.
- Script Editor: Write and save scripts (
.R
files). - Workspace: Stores variables and objects created during the session.
- Help System: Provides built-in documentation.
Starting RGUI on Windows:
- Open R from the Start menu.
- The R Console will appear, where you can enter commands directly.
3. Exploring RStudio – Data Analytics with R
RStudio is a powerful IDE that makes R programming more user-friendly. It provides a well-organized interface for coding and visualization.
Key Components of RStudio:
- Console – Executes R commands.
- Script Editor – Write, edit, and save scripts.
- Environment Pane – Displays variables and objects.
- Files, Plots, Packages, and Help Pane – Manages working directories, visualizations, and documentation.
Running a Script in RStudio:
- Click on File > New File > R Script.
- Write your R code.
- Press Ctrl + Enter to run a line of code.
- Save the script as a
.R
file.
4. Handling Basic Expressions in R , Data Analytics with R
R can handle basic mathematical operations and expressions.
# Basic Arithmetic Operations
5 + 3 # Addition
10 - 2 # Subtraction
4 * 2 # Multiplication
8 / 2 # Division
2^3 # Exponentiation
R follows the PEMDAS rule (Parentheses, Exponents, Multiplication, Division, Addition, Subtraction).
# Order of operations
(3 + 2) * 4 # Output: 20
5. Variables in R
A variable stores a value and can be used for calculations. In R, we use <-
to assign values to variables.
x <- 10
y <- 5
z <- x + y
print(z) # Output: 15
Rules for Naming Variables:
✔️ Variable names are case-sensitive (X
and x
are different).
✔️ They must start with a letter (not a number or special character).
✔️ Avoid using reserved words like if
, for
, while
.
6. Working with Vectors
A vector is a sequence of data elements of the same type. It is the most basic data structure in R.
Creating a Vector:
numbers <- c(1, 2, 3, 4, 5)
print(numbers)
Vector Operations:
sum(numbers) # Sum of elements
length(numbers) # Number of elements
mean(numbers) # Average value
max(numbers) # Maximum value
min(numbers) # Minimum value
Vectorized Operations:
numbers * 2 # Multiplies each element by 2
7. Storing and Calculating Values in R
R allows calculations using stored values.
a <- 10
b <- 20
result <- a + b
print(result) # Output: 30
8. Creating and Using Objects
Objects in R store values, functions, or datasets.
num_var <- 42 # Numeric
char_var <- "R Language" # Character
bool_var <- TRUE # Logical
To check an object’s type:
class(num_var) # Output: "numeric"
9. Interacting with Users
Use readline()
to take user input.
name <- readline(prompt = "Enter your name: ")
print(paste("Hello,", name))
10. Handling Data in R Workspace
Viewing Objects:
ls() # List all objects
Removing Objects:
rm(x) # Remove a single object
rm(list = ls()) # Remove all objects
Saving and Loading Workspace:
save.image("my_workspace.RData") # Save
load("my_workspace.RData") # Load
11. Executing Scripts , Data Analytics with R
To execute an R script:
- Write the script in RStudio.
- Save the file as
script.R
. - Run the script using:
source("script.R")
12. Creating Plots – Data Analytics with R
Basic Scatter Plot:
x <- c(1, 2, 3, 4, 5)
y <- c(2, 4, 6, 8, 10)
plot(x, y, type="o", col="blue", main="Basic Plot")
Histogram:
hist(x, main="Histogram")
Boxplot:
boxplot(y, main="Boxplot")
13. Accessing Help and Documentation in R
Use built-in help functions:
?mean # Help on mean function
help("plot") # Help on plot function
help.start() # Opens R help in the browser
Explore package documentation:
help(package="ggplot2")
For AR-VR Notes | Click Here |
For Big Data Analytics (BDA) Notes | Click Here |
Conclusion
This guide covered:
✔️ Basic operations and expressions in R.
✔️ Working with variables and vectors.
✔️ Writing and executing R scripts.
✔️ Creating plots for data visualization.
✔️ Accessing R’s built-in help system.
Data Analytics with R
FAQ
What is R used for?
R is primarily used for statistical computing, data analysis, and visualization. It is widely used in academia, research, finance, and machine learning.
How do I install R and RStudio?
What is the difference between R and RStudio?
R is the programming language.
RStudio is an IDE (Integrated Development Environment) that makes writing and running R code easier.
How do I create and run an R script?
Open RStudio, go to File > New File > R Script.
Write R code and save the file (.R
).
Run the script using source("script.R")
or click Run in RStudio.
How do I get help in R?
Use built-in functions:
?mean # Get help on a function
help(“plot”) # Detailed help on a function
help.start() # Opens R documentation in a browser
RProgramming #DataScience #Statistics #RStudio #DataAnalysis #MachineLearning #DataVisualization #Coding #Programming #Analytics #BigData