Ivy Jun 01, 2018 No Comments
Have an interview tomorrow? Facing last moment preparation issues? Well, we bring to you this Base R Cheat Sheet to ace up your chances of getting employed.
As Data Exploration and Data Manipulation takes most of the time, chances of being questioned as to how shall you deal with an unstructured data and manipulate them are high.
Getting Started with Libraries
Allows download and install packages from the CRAN repository.
Loads the package in the session in order to allow the use of the functions.
To get the current location of the directory.
To change the current working directory.
Reading and Writing Data
data <- read.csv(“file.csv”)
To read or import data as a CSV file.
To write or export data.
Converting Data Types
To convert into the Boolean form
To convert to numeric
To convert into factors
To calculate natural log.
To calculate exponential
To round a number to n decimal places
To find a correlation between 2 variables
Dealing with Data Frames
df <- data.frame(x = 6:10, y = c( ‘ a’, ‘b’, ‘c’)
Creating a data frame
Accessing a column of a data frame
To look at the whole data set
number of rows and columns in a data frame
Dealing with strings
paste(x, y, sep =’ ‘)
To join multiple vectors together
To find regular expression matches in x
gsub(pattern, replace, x)
To replace matches in x with a string
To convert a string to upper case
To find the number of characters in the string
Plotting a histogram
Plotting bar plots
Plotting a piechart
Plotting values of x on a line (an alternative to boxplot for small values)
Fitting a linear regression model
glm(formula, data=, family=)
Fitting a generalized linear model
To predict on the fitted model
To obtain fitted values