Introduction to R

📘 What is R?

R is a free and open-source programming language and software environment designed for statistical computing, data analysis, and data visualization. It is widely used by data scientists, statisticians, researchers, and analysts to analyze data, build predictive models, and create high-quality visualizations.

Information

R is available for Windows, macOS, and Linux, making it accessible across multiple platforms.

🌟 Why Learn R?

  • Simple syntax for statistical analysis.
  • Excellent support for data visualization.
  • Thousands of community-contributed packages.
  • Strong ecosystem for machine learning and data science.
  • Widely used in academia and industry.

🧭 Features of R

📊 Data Analysis
📈 Visualization
🧠 Machine Learning
đŸ“Ļ Package Ecosystem
Data manipulation
Statistical analysis
Charts
Graphs
Interactive dashboards
Classification
Regression
Clustering
ggplot2
dplyr
tidyr
caret

âš™ī¸ Installing R

👋 Your First R Program

The traditional first program prints a message to the console using the print() function.

Hello World in R

print("Hello, World!")

đŸ”ĸ Variables in R

Variables store values using the assignment operator <-. Although = can also assign values, <- is the preferred style in R.

Variable Example

name <- "Alice"
age <- 24
salary <- 45000

print(name)
print(age)
print(salary)

📚 Basic Data Types

Data TypeDescriptionExample
NumericNumbers25.5
IntegerWhole numbers10L
CharacterText"Hello"
LogicalBoolean valuesTRUE
ComplexComplex numbers3 + 2i

🧮 Basic Arithmetic

Arithmetic Operations

a <- 10
b <- 5

a + b
a - b
a * b
a / b
a ^ b
a %% b

đŸ“Ļ Common Data Structures

A vector stores elements of the same data type.

Vector

numbers <- c(10, 20, 30, 40)
print(numbers)

A matrix is a two-dimensional collection of similar data.

Matrix

m <- matrix(1:9, nrow = 3)
print(m)

A data frame stores tabular data where each column may have a different type.

Data Frame

students <- data.frame(
  Name = c("Alice", "Bob"),
  Age = c(21, 22)
)

print(students)

A list stores multiple objects of different types.

List

info <- list(
  name = "Alice",
  age = 22,
  marks = c(90, 85, 88)
)

print(info)

📊 Built-in Functions

Useful Functions

numbers <- c(10, 20, 30, 40, 50)

sum(numbers)
mean(numbers)
max(numbers)
min(numbers)
length(numbers)

📈 Simple Plot

One of R's strengths is its ability to generate beautiful visualizations with minimal code.

Basic Plot

x <- c(1,2,3,4,5)
y <- c(2,4,6,8,10)

plot(x, y, type="b", col="blue")

đŸŽ¯ Real-World Applications

  • 📊 Business analytics
  • 💹 Financial modeling
  • đŸ§Ŧ Bioinformatics
  • đŸĨ Healthcare research
  • 🤖 Machine learning
  • 📈 Data visualization

💡 Best Practices

Best Practice

Use meaningful variable names, write reusable functions, comment important code, organize scripts into modules, and install only trusted packages from CRAN.

📖 Learning Roadmap

📝 Summary

R is one of the most powerful programming languages for data analysis, statistics, and visualization. Its rich package ecosystem, extensive community support, and ease of use make it an excellent choice for beginners as well as experienced data professionals. Mastering the fundamentals of R provides a strong foundation for advanced topics such as machine learning, data engineering, and statistical modeling.

>>"The goal is to turn data into information, and information into insight."