R Tutorial for Beginners
This R Tutorial is a beginner-friendly guide to R programming for data analysis, statistics, charts, and file handling. It starts with R installation and script basics, then moves through variables, data types, operators, conditions, loops, functions, strings, vectors, lists, matrices, data frames, data import, plots, and basic statistical functions.
Use this page as an ordered R learning path. New learners can follow the sections from top to bottom, while users who already know programming basics can jump directly to a specific R topic from the tutorial index.
What is R programming language?
R is an open-source programming language and software environment used for statistical computing, data analysis, and graphics. It is used to store data, clean data, run calculations, summarize results, and draw visualizations such as plots and charts.
An R program can be written as commands in the console or saved as an R script file. For practical learning, it is better to write small script files, run them, inspect the output, and then extend the examples step by step.
Features of R Programming for Data Analysis
- R is open source and free to use.
- R has built-in support for statistics, vectors, matrices, data frames, and plotting.
- R can be used from the command line, from R script files, or through IDEs such as RStudio.
- R can read and write common data formats such as CSV and Excel files with the right functions or packages.
- R supports packages, so you can extend it for data cleaning, visualization, reporting, machine learning, and domain-specific analysis.
- R makes it easier to keep analysis code, results, tables, and plots in a reproducible workflow.
First R Program Example
The following simple R program creates a numeric vector, calculates the mean value, and finds the highest value.
marks <- c(72, 85, 90, 66, 78); mean(marks); max(marks)Output:
[1] 78.2 [1] 90Recommended R Learning Order
| Learning stage | R topics | Learning outcome |
|---|---|---|
| Start | Installation, script files, syntax | Run commands and save R code in a script file. |
| Programming basics | Variables, data types, operators, conditions, loops, functions | Write reusable R programs and control program flow. |
| Core data structures | Vectors, lists, matrices, data frames | Store, access, transform, and combine data. |
| Data work | CSV, Excel, missing values, type conversion | Import, inspect, clean, and export data. |
| Analysis | Plots, graphs, mean, median, mathematical functions | Create basic visuals and calculate summary values. |
R Tutorial Index

In our R Tutorial, we shall take you through the following topics.
Get Started with R Programming
The following tutorials help you set up R on your computer and understand the basic structure of an R script file.
R Variables and Datatypes
Variables store values during program execution. Data types describe the kind of value stored in a variable, such as numeric, integer, logical, character, or missing value.
R Operators for Calculations and Conditions
R operators are used for arithmetic calculations, comparisons, logical expressions, assignment, and other operations. Operators are required before learning conditions, loops, and data filtering.
R Decision Making with if, if-else, else-if, and switch
Decision making statements execute a block of code only when a condition is satisfied. In R programming, these statements are used to validate input, handle special cases, and choose different calculations based on data values.
R if statement with logical operators in condition
R Looping with repeat, while, and for
Looping statements execute a block of code repeatedly. In R, loops are useful when you need to process values one by one, repeat a calculation until a condition changes, or inspect items in a vector, list, matrix, or data frame.
R Functions for Reusable Code
A function is a set of statements that can take arguments, perform a task, and return a result. R has many built-in functions for statistics, mathematics, strings, dates, and plots. You can also create your own functions to avoid repeating the same code.
R Strings and Text Operations
A string is a sequence of characters. In R, strings are used for names, labels, categories, file paths, messages, and text data.
R Data Frames for Tabular Data
R data frames store tabular data in rows and columns. A data frame can contain columns of different types, such as numbers, strings, logical values, and dates. For many beginner data analysis tasks in R, data frames are the main structure used after importing data.
students <- data.frame(name = c('Asha', 'Ravi', 'Meera'), marks = c(82, 76, 91), passed = c(TRUE, TRUE, TRUE)); students; summary(students$marks)- R Data Frame
- R – Access Element at (i,j) in Data Frame
- R – Create Empty Data Frame
- R – Create Data Frame
- R – Add Column to Data Frame
- R – Reset Row Numbers of Data Frame
- R – Replace NA with 0 in Data Frame
- R – Rename Column(s) of Data Frame
- R – Delete Duplicate Rows in Data Frame
- R – Remove Row(s) in Data Frame
- R – Remove NA Rows in DataFrame
- R – Delete Column(s) in Data Frame
- R – Sort Data Frame by Column
- R – Apply Function For Each Row in Data Frame
- R – Filter Data Frame with NA rows
- R – Convert List to Data Frame
- R – Convert Data Frame to Matrix
- R – Convert Matrix to Data Frame
- R – Combine Data Frames
- R – Compare Data Frames
- R – Import Excel to Data Frame
- R – Structure of Data Frame
- R – Summary of Data Frame
R Type Conversion Between Common Data Types
R allows us to convert a value from one datatype to another. Type conversion is common when imported data stores numbers as strings or when a calculation needs a specific data type.
R Vectors for One-Dimensional Data
An R vector is a sequence of elements of the same datatype. Vectors are fundamental in R because many functions and operators work on all elements of a vector at once.
- R Vectors
- R – Create Vector
- R – Get Vector Length
- R – Access Items in Vector
- R – Iterate over Items of Vector
- R – Sort Vectors
- R – Reverse Vector
- R – Check if Specific Item is present in Vector
- R – Logical Vectors
- R – Integer Vectors
- R – Double Vectors
- R – Character Vectors
- R – Get Type of Vector
- R – Check if type of Vector is Logical
- R – Check if type of Vector is Integer
- R – Check if type of Vector is Double
- R – Check if type of Vector is Character
- R – Convert Logical Vector into Integer Vector
- R – Convert Character Vector into Integer Vector
- R – Vector Recycling
R Lists for Mixed Data
An R list is a sequence of elements where the elements can be of different datatypes. Lists are useful when you need to group related values such as vectors, strings, numbers, data frames, or model results into one object.
- R – Lists
- R – Create Empty List
- R – Create List
- R – Get List Length
- R – Append Item to List
- R – Loop through Items in List
- R – Check if Specific Item is present in List
- R – Reverse List
- R – Join Lists
R Matrix Operations
An R matrix stores data in rows and columns where all elements have the same datatype. Matrices are commonly used for numerical calculations, linear algebra, and structured two-dimensional data.
- R Matrix
- R – Create Matrix
- R – Check if R Object is a Matrix
- R – Get Element at Given Row, Column of Matrix
- R – Get Specific Row of Matrix
- R – Get Specific Column of Matrix
- R – Get Multiple Rows of Matrix
- R – Get Multiple Columns of Matrix
- R – Matrix Multiplication
- R – Transpose Matrix
- R – Inverse Matrix
- R – Correlation Matrix
R Date and Time Values
Date and time values are used when data contains timestamps, calendar dates, transaction dates, log times, or time-based measurements.
Data Import and Export in R from CSV and Excel Sources
The following tutorials deal with reading different file types and loading data from those files into R data objects, and how to write data from R objects to files.
sales <- read.csv('sales.csv'); head(sales); write.csv(sales, 'sales_cleaned.csv', row.names = FALSE)Charts, Plots, and Graphs in R
R can create charts and graphs directly from vectors, matrices, and data frames. Start with base plotting functions such as plot() and barplot() before moving to advanced visualization packages.
R plot() Function Tutorials
- R – Draw Plot from two Vectors X, Y
- R – Draw Line Plot
- R – Change Color of Plot
- R – Set Plot Line Width or Thickness
- R – Set Plot Title
- R – Set X, Y axes Labels
R barplot() Function Tutorials
- R Bar Plot – From Matrix
- R Bar Plot – Set Main Title
- R Bar Plot – Set X, Y axes Labels
- R Bar Plot – Set Width for Bars
- R Bar Plot – Set Space between Bars
- R Bar Plot – Set Color for Bars
- R Bar Plot – Set Names for Bars
- R Bar Plot – Draw without Axes
- R Bar Plot – Set Border Color for Bars
- R Bar Plot – With Horizontal Bars
Statistical Analysis in R
R includes functions for descriptive statistics and statistical analysis. Beginners can start with values such as mean and median from vectors and then apply the same idea to columns in a data frame.
R Mathematical Functions
R has built-in mathematical functions for common tasks such as finding absolute value, maximum value, minimum value, square root, and more. These functions work with individual values and, in many cases, with vectors.
R Packages and Help Commands for Beginners
R can be extended with packages. A package is a collection of functions, data, documentation, and examples. Beginners should first learn base R syntax and then install packages only when a task needs them.
install.packages('readxl'); library(readxl); ?read_excelCommon R Programming Mistakes to Avoid
- Forgetting that R indexes from 1: The first item in a vector is at position
1, not0. - Mixing data types in a vector: A vector stores values of the same basic type. If numbers and strings are mixed, R may coerce the values to one type.
- Ignoring NA values: Many calculations return
NAwhen missing values are present unless they are handled properly. - Confusing a matrix with a data frame: A matrix holds one data type, while a data frame can hold different column types.
- Skipping script files: Commands typed only in the console are harder to reuse and debug than code saved in an R script file.
QA Checklist for Reviewing This R Tutorial Page
- Confirm that every new R code block uses valid R syntax and the PrismJS class
language-r. - Confirm that output-only blocks use the
outputclass. - Check that beginner topics are ordered from setup and syntax to data structures, file import, plots, and statistics.
- Verify that vectors, lists, matrices, and data frames are described accurately.
- Make sure the existing R tutorial image and existing tutorial URLs remain present in the content.
- Check that FAQ answers are specific to learning R programming.
R Tutorial FAQs for Beginners
What should I learn first in R programming?
Start with installing R, running commands, writing an R script file, creating variables, understanding data types, and using vectors. After that, learn conditions, loops, functions, data frames, file import, plots, and basic statistics.
Is R used only for statistics?
No. R is strongly associated with statistics, but it is also used for data cleaning, data visualization, reporting, research workflows, dashboards, simulations, and reproducible analysis.
What is the difference between a vector and a data frame in R?
A vector is a one-dimensional collection of values of the same type. A data frame is a two-dimensional table with rows and columns, where different columns can have different types.
How do I handle missing values in R?
Missing values are represented by NA in R. You can detect them with is.na(), remove incomplete rows when appropriate, replace them with another value, or use arguments such as na.rm = TRUE in supported summary functions.
Can I learn R without prior programming experience?
Yes. A beginner can learn R by starting with small examples and practicing one topic at a time. The most important early skills are understanding objects, vectors, functions, data frames, and how to read error messages.
Official R Documentation and Beginner Learning References
You may refer to the following references for R documentation and additional beginner learning material.
What You Can Do After Completing This R Tutorial
After working through this R tutorial index, you should be able to write basic R scripts, use R data types and operators, control program flow, create functions, work with vectors, lists, matrices and data frames, import CSV and Excel data, create simple plots, and calculate common statistical values.
TutorialKart.com