Introduction to R Programming - R Programming For Data Science | Lecture Notes - YNetStudyHub
R Programming For Data Science

Introduction to R Programming

1 mins read 152 words Topic 1 of 28
Study with AI Tutor Learn 2× faster Instant Q&A Quiz practice
Launch AI Lesson
Text Size:
PDF Save

An overview of the R programming language, its features, and how it is used in the context of data science.

Introduction to R Programming
Quick‑reference guide for beginners


1. What Is R?

Aspect Description
Type Open‑source language & environment for statistical computing and graphics
Origin Developed in 1993 by Ross Ihaka & Robert Gentleman (University of Auckland)
License GNU GPL (free to use, modify, distribute)
Core Strengths Data manipulation, statistical modeling, reproducible research, high‑quality visualizations
Community CRAN (Comprehensive R Archive Network) hosts > 19,000 packages; active mailing lists, Stack Overflow, R‑Bloggers

2. Getting Started

Step Action
Install R Download from https://cran.r-project.org (Windows, macOS, Linux)
Install an IDE RGui (basic), RStudio (most popular), VS Code with R extension, or Jupyter notebooks
Run a script Rscript myfile.R (command line) or click Run in the IDE
Package management install.packages("pkg") – install
library(pkg) – load
remove.packages("pkg") – uninstall

3. Basic Syntax & Data Types

Category Example Notes
Comments # This is a comment Whole line or trailing comment
Assignment x <- 10 or x = 10 <- is idiomatic; = works inside function calls
Vectors v <- c(1, 2, 3) Homogeneous; recycling rules apply
Sequences seq(1, 10, by = 2) or 1:10 Shortcut for integer sequences
Matrices m <- matrix(1:9, nrow = 3, byrow = TRUE) 2‑D, column‑major storage
Lists lst <- list(name="Alice", age=30, scores=c(90,85)) Heterogeneous, can contain any object
Data frames df <- data.frame(id=1:3, gender=c("F","M","F")) Tabular data; each column is a vector
Factors f <- factor(c("yes","no","yes")) Categorical data with levels
Logical TRUE, FALSE Used for subsetting, conditionals
Missing values NA, NaN, NULL is.na(), is.nan(), is.null() to test

4. Essential Operations

4.1 Indexing & Subsetting

v[2]                # 2nd element
v[ c(1,3) ]         # elements 1 and 3
v[ v > 2 ]          # conditional subset
df[1:2, "age"]      # rows 1‑2, column "age"
df$age              # shortcut for column
df[[ "age" ]]       # same as df$age

4.2 Vectorized Arithmetic

x <- 1:5
y <- x * 2          # element‑wise multiplication
z <- x + y          # addition

All arithmetic is automatically vectorized; no explicit loops needed.

Topic Concept Map
Ask AI Tutor 24/7 Live

Click any prompt to explore this topic interactively with your AI Tutor:

Explain in simple terms Give me 3 practice exam questions Summarize key principles in 5 points
Unit Syllabus 28 Topics
Introduction to R Programming
Data Types and Data Structures in R
Upgrade
Data Manipulation with dplyr
Upgrade
Data Visualization with ggplot2
Upgrade
Working with External Data Sources
Upgrade
Statistical Analysis with R
Upgrade
Machine Learning Basics in R
Upgrade
Text Mining and Natural Language Processing in R
Upgrade
Time Series Analysis in R
Upgrade
R Markdown for Reproducible Research
Upgrade
Introduction to R Programming
Upgrade
Data Types and Data Structures in R
Upgrade
Control Structures and Functions in R
Upgrade
Data Import and Export in R
Upgrade
Data Wrangling and Cleaning
Upgrade
Data Visualization with ggplot2
Upgrade
Statistical Analysis with R
Upgrade
Machine Learning with R
Upgrade
Reporting and Presenting Results
Upgrade
Best Practices and Advanced Topics
Upgrade
Introduction to R Programming
Upgrade
Data Manipulation in R
Upgrade
Data Visualization with ggplot2
Upgrade
Statistical Analysis in R
Upgrade
Working with APIs and Web Scraping in R
Upgrade
Machine Learning Basics in R
Upgrade
Text Mining and Natural Language Processing in R
Upgrade
Shiny App Development
Upgrade