Rstats 101
  • Home
  • LLM
  • dplyr
  • tidyr
  • ggplot2
  • Statistics
  • How-To
  • Base R

How-To Guides

Practical how-to guides for common R programming tasks.

3 Useful Matrix Functions in R: matrix(), is.matrix() and as.matrix()

Matrix is on of the fundamental data structures in R. In this tutorial, we will see three key matrix functions in R, matrix(), is.matrix(), and…

Computing Correlation Between Multiple Variables in a dataframe

Learn computing correlation between multiple variables in a dataframe with this comprehensive R tutorial. Includes practical examples and code…

How To Check If One or More Elements is in a Vector

In this tutorial, we will learn about is.element() function available in base R and use it to check if one or more elements is present in a vector.

How To find levels of a factor in R

Learn how to perform find levels of a factor in R. Step-by-step statistical tutorial with examples.

How to Calculate Rolling Mean in R

Learn how to perform calculate rolling mean in R. Step-by-step statistical tutorial with examples.

How to Compute Compound Interest with Tidyverse

Learn how to compute compound interest with Tidyverse in R. Practical tutorial with examples.

How to Compute row means

Learn how to compute row means with this comprehensive R tutorial. Includes practical examples and code snippets.

How to Convert Numerical Variable into a Categorical Variable in R

Learn how to perform convert numerical variable into a categorical variable in R. Step-by-step statistical tutorial with examples.

How to Convert a List to a dataframe in R

List data structure in R is a useful structure store different data types. In this tutorial, we will learn how to convert a list into a dataframe.…

How to Create a dataframe from vectors in R

In this tutorial, we will learn how to create a dataframe from scratch in R. We will learn to create a dataframe from two vectors of same length.…

How to Find difference between two dates as days, weeks, months and years

In this tutorial we will learn how to find the difference between two date objects in R in terms of days, months, and years. We will learn how to…

How to Generate Random Numbers from Uniform Distribution

In this tutorial, we will learn how to simulate or generate random numbers from uniform distribution. In R, with the in-built function runif() we…

How to Measure Running Time in R (with two examples)

!Running time in R with Sys.time() and system.time() Running time in R with Sys.time() and system.time()In this tutorial, we will learn how to…

How to Randomly Replace Values in a Matrix to NAs

Learn how to randomly replace values in a matrix to nas with this comprehensive R tutorial. Includes practical examples and code snippets.

How to Replace NA values in a dataframe with Zeros?

In this tutorial, we will learn how to replace all NA values in dataframe with a specific value like zero in R. !How to replace Missing Values with…

How to Replace NA values with Column Mean

One of the ways to deal with missing values (or NAs) is to replace them with mean values (under certain assumptions). The process is called…

How to Replace NAs with Column mean using tidyverse

Learn how to replace nas with column mean using tidyverse with this comprehensive R tutorial. Includes practical examples and code snippets.

How to Save Dataframe into XLSX file in R

In R, there are many ways to save a dataframe as Excel file .xlsx. In this tutorial, we will use the R package openxlsx and learn how to save a…

How to add currency symbols to columns of a table with gt()

Learn how to add currency symbols to columns of a table with gt() with this comprehensive R tutorial. Includes practical examples and code snippets.

How to calculate a moving average in R

Learn calculate a moving average in r with clear examples and explanations.

How to calculate cumulative sum in R

Learn how to perform calculate cumulative sum in R. Step-by-step statistical tutorial with examples.

How to calculate products with prod() in R

Learn calculate products with prod() in r with clear examples and explanations.

How to calculate time differences in R

Learn calculate time differences in r with clear examples and explanations.

How to compute annualized return of a stock with tidyverse

Learn how to compute annualized return of a stock with tidyverse in R. Practical tutorial with examples.

How to compute inverse of a matrix in R

In this tutorial, we will show how to compute inverse of matrix in R. Computing inverse of a matrix is core to multiple applications.

How to compute mean in R

In this tutorial, we will learn how to use mean() function in R to compute mean (or average) of a vector.

How to compute proportion with tidyverse

Learn how to compute proportion with tidyverse in R. Practical tutorial with examples.

How to compute row means in R

In this tutorial, we will learn about rowMeans() function in base R and use it to calculate mean of all rows in a matrix or a dataframe. We will see…

How to convert a list to a dataframe in R

Learn convert a list to a dataframe in r with clear examples and explanations.

How to convert a matrix to a tidy table

Learn how to convert a matrix to a tidy table with this comprehensive R tutorial. Includes practical examples and code snippets.

How to create a directory if it does not exist in R

In this tutorial we will learn how to create a directory if it does not exist already using R. We will be using two base R functions, one of…

How to find installed R version from RStudio

In this tutorial, you will learn three different ways to identify the version of R installed in your computer.

How to format currency in gt tables in R

Learn format currency in gt tables in r with clear examples and explanations.

How to get product of all elements in a column

Learn how to get product of all elements in a column with this comprehensive R tutorial. Includes practical examples and code snippets.

How to remove unused factor levels with droplevels() in R

Learn remove unused factor levels with droplevels() in r with clear examples and explanations.

How to sort a dataframe by multiple columns in R

Learn sort a dataframe by multiple columns in r with clear examples and explanations.

How to sort columns alphabetically

Learn how to sort columns alphabetically with this comprehensive R tutorial. Includes practical examples and code snippets.

How to use cbind() function in R

Learn how to perform use cbind() function in R. Step-by-step statistical tutorial with examples.

How to use dollar $ operator in R

Learn how to perform use dollar $ operator in R. Step-by-step statistical tutorial with examples.

How to use outer function in R

In this tutorial, we will learn how to use outer() function in R. The outer() function in R is a useful tool for applying a function to all pairs of…

List of Built in Datasets in R

Complete guide to list of built in datasets in R programming. Tutorial with practical examples and code.

Many linear regression models with tidyverse

Learn many linear regression models with tidyverse in R. Practical tutorial with examples.

Remove rows with missing values using drop_na() in R

Complete guide to remove rows with missing values using drop_na() in R programming. Tutorial with practical examples and code.

Remove rows with missing values using na.omit() in R

Dealing with missing values is a common activity while doing data cleaning and analysis. In R missing values typically represented as NA. Often you…

Simple Barpots and reordering bars in R

Complete guide to simple barpots and reordering bars in R programming. Tutorial with practical examples and code.

Simple linear regression with tidyverse

Learn simple linear regression with tidyverse in R. Practical tutorial with examples.

What is R?

R is a programming language originally developed for doing statistical computing. It is similar to the S programming language that was developed at…

colSums in R - compute sum of all columns in a dataframe or matrix

In this tutorial, we will learn about colSums() function in base R and use it to calculate sum of all columns in a matrix or a dataframe. We will…

dplyr if_else(): Create new variable from existing variable

Master dplyr if_else() to create new variable from existing variable. Complete R tutorial with examples using real datasets.

dplyr rename(): How to rename column in r with dplyr

Master dplyr rename() to how to rename column in r with dplyr. Complete R tutorial with examples using real datasets.

dplyr’s arrange(): Sort a Dataframe Columns

In this tutorial, we will learn how to sort a dataframe by a column in R. We will see three examples of using tidyverse’s arrange() function to sort…

duplicated() function in R: Find duplicated elements in a vector or dataframe

In this tutorial, we will learn about the base R function duplicated() and how can we use duplicated() function to find if an element in a vector is…

gsub() in R to replace all matching patterns

In this tutorial, we will learn about gsub() function in R to replace all matching patterns in a string.

head() in R to view the first elements

head() function in R is one of the most useful functions that lets you quickly get a peek at the data you have in a R object. Using head() function…

list.files() in R: list files in a directory

Learn list.files() in r: list files in a directory with this comprehensive R tutorial. Includes practical examples and code snippets.

ls() in R: list objects/variables in your environment

Often while working in R, you might want to check your environments for all the objects you have created and available in your environment. ls()…

runif()- generate uniform random numbers

One way to generate uniformly distributed numbers in R is use the runif() function. runif is short for “random uniform”. R has other random number…

sample() function in R for random sampling

Learn sample() function in r for random sampling with this comprehensive R tutorial. Includes practical examples and code snippets.

seq() function to create sequences

seq() function in R is one of the base R functions that is useful in creating sequences. In this tutorial, we will see multiple examples of creating…

tidyverse all_of(): select columns from a vector

Learn tidyverse all_of(): select columns from a vector with this comprehensive R tutorial. Includes practical examples and code snippets.

No matching items

    Featured Tutorial

    Introduction to Mixed Effects Models

    Learn when and why to use mixed models for longitudinal data with lme4

    Browse by Topic

    dplyr

    59 tutorials

    Data manipulation with filter, select, mutate, joins & more

    tidyr

    22 tutorials

    Reshape data with pivot_wider, pivot_longer, separate & unite

    ggplot2

    22 tutorials

    Create beautiful visualizations with the grammar of graphics

    Statistics

    31 tutorials

    T-tests, ANOVA, regression, correlation & more

    How-To

    53 tutorials

    Practical guides for common R tasks

    Base R

    21 tutorials

    Core R programming fundamentals

    Copyright 2025 Rstats101. All rights reserved.

     
    • About

    • Privacy Policy