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.

#### Data Science with R Programming ## R Cheat Sheet

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

### Basic Syntax

#### Purpose

<- or  =

Assignment

#

Comment

/

Division

<<-

Global Assignment

%%

Remainder

*

Scalar Multiplication

%/%

Integer Division

%*%

Matrix Multiplication

v

First vector element

### Accessing Help

#### 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

#### Free Course: R Programming for Beginners

Learn R Programming from Experts ### Dataframe

#### 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

#### 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

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

#### Free Course: Machine Learning Algorithms

Learn the Basics of Machine Learning Algorithms ### Vector

#### 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

#### 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

#### Artificial Intelligence Engineer

Your Gateway to Becoming a Successful AI Expert ### Hypothesis

#### 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

#### 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

#### 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

#### 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

#### 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

#### 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! Simplilearn