R is one of the most frequently used programming languages in the Machine Learning and Data Science fields and is used extensively in both academia and a variety of industries. Many data scientists now use R as their preferred computing environment since it is simple to learn, open-sourced, and capable of handling statistical computations and complex data.

Excited to learn R? In this article, we will be exploring an overview of R using an easy-to-understand cheat sheet. Use it as a convenient, high-level guide to starting with R immediately.

R Cheat Sheet

Here, we will explore the various shortcuts and symbols related to R.

Basic Syntax

Operator

Purpose

<- or  =

Assignment

#

Comment

/

Division

<<-

Global Assignment

%%

Remainder

*

Scalar Multiplication

%/%

Integer Division

%*%

Matrix Multiplication

v[1]

First vector element

Accessing Help

Function Name

Purpose

help.start()

opens help

class(df_name)

Returns class of the given object

?tidyverse

Shows tidyverse package documentation

str(df_name)

Returns information and structure of the given object

?function_name

Shows in-built functions’ documentation

??”some_input”

Shows a given input’s documentation

Dataframe

Method/Definition

Description

summary(df_name)

Returns the statistics of data in a descriptive format

view(df_name)

Opens the editor

df_name = data.f­ram­e(s­tudent­ID=­1:5­, year=c­("1960",­"­1980","1990­"­,"1998",­"­2001"),­sco­re=­c(6,1,­3,2,2))

Dataframe definition

Utility

Method

Purpose

order(index) 

To find the index to sort a vector

apply(data, axis, function_name)

To apply data to function in the particular axis

data = read.csv(file.choose())

To read data from the file explorer

dim()

To find dimensions of matrix/dataframe/vector

lapply(data, function_name)

To apply the data to the function

getwd()

Gets the working directory

length()

To find the vector length

install.packages(“package_name”)

Installs the required R package

names()

Returns the column names

setwd(“C:/file/path”)

To set the current working directory

rapply(data, function_name, how)

Depending on the value of how, the data is applied to the function

sort()

To sort a vector

rm(variable_name)

To remove the variable

detach(“package name”)

Detaches the given package

ls()

To list all the variables

library(“package name”)

Makes contents of the given package ready to use

Vector

Method

Purpose

range(vec)

To find the range of a vector

num = c(3,7,­2,1­,8,5)

Defining a numeric vector

rep(1:­8, t­imes=2)

Replicates the elements of the vector by the given number of times

sd(vec)

To find the standard deviation of a vector

chr = c("rte",­"­qhz ­")

Defining a character vector

var(vec)

To find the variance of a vector

log = c(FALSE­, ­FALSE, TRUE)

Logical vector

whi­ch.m­ax­(vec)

To find the position of the max value

which.m­in­(ve­c)

To find the position of the min value

mean(vec)

To find the mean of the values of a vector

Matrix and Arrays

Method

Purpose

rbind(­mat­rix1,matrix2)

To row bind matrix1 and matrix2

cbind(­matrix­1,matrix2)

To column bind matrix1 and matrix2

mat = matrix­(1:15, nrow=3, ncol=5)

To define a matrix

1D = array(­1:14)

To define a 1-dimens­ional array

2D = array(­1:20, dim = c(1,3))

To define a 2-dimens­ional array

3D = array(­1:20, dim = c(1,4,5))

To define a 3-dimens­ional array

Hypothesis

Method

Purpose

aov()

To find ANOVA or Analysis of Variance

wilcox.te­st(­data)

To find the Wilcox test on the given data

t.test­(data)

To find 1 sample t-test of the given data

cor.te­st(­dat­a1,­data2)

To find the correl­ation test of the given data

t.test­(da­ta1­,data2)

To find the 2 sample t-test of the given data

chisq.t­es­t(data)

To find the Chi-square test of the given data

t.test­(pr­e, p­ost­, pa­ire­d=TRUE)

To find the paired sample t-test of the given data

shapir­o.t­est­(data)

To find the Shapiro test of the given data

Statistics and Descriptive Statistics

Method

Purpose

colSum­s(d­ata[])

To find the column sum of a particular column of the given data

rowSum­s(d­ata[])

To find the row sum of a particular row of the given data

summar­y(lm(y ~ x1 + x2 + x3, data=m­ydata))

To find the multiple regression of a given data

cluster = kmeans­(data)

To find the kmeans cluster analysis of a given data

summar­y(glm(y ~ x1 + x2 + x3, family­="", data=m­ydata))

To find the classi­fic­ation of a given data

colMea­ns(­data[])

To find the column mean of a particular column of the given data

rowMea­ns(­data[])

To find the row mean of a particular row of the given data

Visualization

Method

Purpose

geom_hist()

To find the histogram of a given data

coord_­flip()

To flip the x and y coordi­nates of a given point

ggplot­(data = NULL, mapping = aes(), ...)

To initia­lize a ggplot object of a given data

geom_d­ensity()

To produce a density plot of a given data

facet_­grid()

To lay out panels in a grid of a given data

geom_point()

To produce scatter plots of a given data

qplot(­data, line=T­RUE­,...)

To produce the quantile plot of a given data

geom_bar()

To produce a bar graph of a given data

Strings

Method

Purpose

paste (…, sep = " ", collapse = NULL)

Concat­enate the vectors after converting to character

to­lower()

Converts the given text to ­lower case characters

toupper()

Converts the given text to ­upper case characters

toStri­ng(x)

A helper function to produce a single character string

substr­ing­(ch­r, n, n)

To replace or retrieve the substring of a given string

Probability

Method

Purpose

rexp(n)

To find the Expone­ntial distri­bution of n

runif(n, min = 0, max = 1)

To find the Uniform distri­bution of n

rbinom(n, size, prob)

To find the Binomial distri­bution of n

rnorm(­n, m­ean, sd)

To find the Normal distri­bution of n

rpois(­n, size)

To find the Poisson distri­bution of n

Loops

Statement

Purpose

if(condi­tion){ block of statements } else { block of statements }

if-else statements format

while(condi­tion){ block of statements }

while loop format

for(variable in the sequence){ block of statements }

for loop format

Learn data exploration, data visualization, predictive analysis, R packages, data structures in R with the Data Science with R Certification. Check out the course now!

Want to learn more?

In this article, we covered all the basics of R with all the required shortcuts. To learn more about R and become a machine learning expert, check out Simplilearn’s Data Science with R Certification Course!

Data Science & Business Analytics Courses Duration and Fees

Data Science & Business Analytics programs typically range from a few weeks to several months, with fees varying based on program and institution.

Program NameDurationFees
Professional Certificate Program in Data Engineering

Cohort Starts: 2 Jan, 2025

7 months$ 3,850
Professional Certificate in Data Science and Generative AI

Cohort Starts: 6 Jan, 2025

6 months$ 3,800
Post Graduate Program in Data Analytics

Cohort Starts: 13 Jan, 2025

8 months$ 3,500
Caltech Post Graduate Program in Data Science

Cohort Starts: 13 Jan, 2025

11 months$ 4,000
Professional Certificate in Data Analytics and Generative AI

Cohort Starts: 13 Jan, 2025

22 weeks$ 4,000
Data Scientist11 months$ 1,449
Data Analyst11 months$ 1,449

Get Free Certifications with free video courses

  • Introduction to Data Science

    Data Science & Business Analytics

    Introduction to Data Science

    7 hours4.677.5K learners
  • Introduction to Data Visualization

    Data Science & Business Analytics

    Introduction to Data Visualization

    9 hours4.528K learners
prevNext

Learn from Industry Experts with free Masterclasses

  • Land a Data Analyst Job in 2025: Tips for Recruiter Outreach & Interviews

    Data Science & Business Analytics

    Land a Data Analyst Job in 2025: Tips for Recruiter Outreach & Interviews

    27th Jan, Monday9:30 PM IST
  • Secrets to Transition into Data Science from a Non-Tech Background

    Data Science & Business Analytics

    Secrets to Transition into Data Science from a Non-Tech Background

    9th Jan, Thursday9:30 PM IST
  • Crack the Code to Data Analytics: Expert Tips for Non-Data Professionals

    Data Science & Business Analytics

    Crack the Code to Data Analytics: Expert Tips for Non-Data Professionals

    16th Dec, Monday9:30 PM IST
prevNext