R is a statistical computing and graphics programming language that you can use to clean, analyze, and graph data. It is widely used by researchers from various disciplines to estimate and display results and by teachers of statistics and research methods. This book is a detailed guide for beginners to understand R with an explanation of core statistical and research ideas.
One of the powerful characteristics of R is that it is open-source, which means that anyone can access the underlying code used to run the program and add their own code for free. It will always be able to perform the latest statistical analyses as soon as anyone thinks of them. R corrects mistakes quickly and transparently and has put together a community of programming and statistical experts that you can turn to for help.
Mastering R: A Beginner’s Guide not only explains how to program but also how to use R for visualization and modeling. The fundamental principles of R explained here are helpful to beginner and intermediate users interested in learning this highly technological and diverse language.
Author(s): Sufyan bin Uzayr
Series: Mastering Computer Science
Publisher: CRC Press
Year: 2023
Language: English
Pages: 296
City: Boca Raton
Cover
Half Title
Series Page
Title Page
Copyright Page
Dedication
Contents
About the Editor
Acknowledgments
Zeba Academy – Mastering Computer Science
CHAPTER 1: Introduction to R
DATA SCIENCE
Data Science Life Cycle
Data Science Process
INTRODUCTION TO R
ENVIRONMENT OF R
ORIGIN OF R
HISTORY
R VERSUS PYTHON
How Does R Work?
R Is Software
Usage
Use of the R Programming Language in Various Areas
R in Research and Academics
R Use Cases in Research and Academia
R in IT Sectors
R in Finance
R for Social Media
R in Banking
R in Healthcare
R in Manufacturing
R in the Governmental Department
SOME OTHER APPLICATIONS OF R
THE MOST POPULAR R PACKAGES
R PACKAGE
COMPREHENSIVE R ARCHIVE NETWORK
IDE AND EDITORS
RStudio
R Tools for Visual Studio
Rattle
Installing Rattle
Installing on Ubuntu 22.04
Installing on Macintosh OS X (Leopard and Lion)
DESIGN OF THE R SYSTEM
INTRODUCTION TO RSTUDIO
How to Install RStudio
Installing R
Installing RStudio
DOWNLOAD AND INSTALL R
INSTALLING RSTUDIO ON WINDOWS
RSTUDIO
RSTUDIO INSTALLATION
RStudio Desktop
RStudio Server
RSTUDIO USER INTERFACE
StatET for R
Installation of StatET
For Windows
For Mac
KWard
Tinn-R
R AnalyticFlow
Why AnalyticFlow?
ADVANTAGES OF R PROGRAMMING
DISADVANTAGES OF R PROGRAMMING
CHAPTER SUMMARY
NOTES
CHAPTER 2: Handling Data with R
GETTING STARTED WITH THE RSTUDIO APPLICATION
THE CONSOLE
The Text Editor
File Browser Tab
“Environment” Tab
Code Completion
Retrieving Previous Commands
Console Title Bar
Keyboard Shortcuts
Basic Syntax in R Programming
R Syntax
Variables in R
Creating Variables in R
Print/Output Variables
Comments
Types of Comments
Comments in R
Single-Line Comments in R
Keywords in R
Quick Navigation between Windows
Console Keyboard Shortcuts
Completions (Console and Source)
Help
Debug
Plots
Git/SVN
Session
Terminal
Accessibility
Main Menu (Server)
DATA TYPES IN R
Logical Data Type
Numeric Data Type
Integer Data Type
Complex Data Type
Character Data Type
Raw Data Type
Find Data Type of an Object
Type Verification
Convert an Object’s Data Type to Another
NOMENCLATURE OF R VARIABLES
IMPORTANT METHODS FOR VARIABLES
class() Function
ls() Function
rm() Function
Scope of Variable in R
VARIABLE NAMING CONVENTION
The Scope of a Variable
How to Access Local Variable Globally
How Does the Super Assignment Operator Work?
R Programming Environment
DATA STRUCTURE IN R
GETTING DATA IN R
CHAPTER SUMMARY
NOTES
CHAPTER 3: Variables and Operators
INTRODUCTION
Rules for Writing Identifiers in R
Constants in R
Valid Identifiers in R
Invalid Identifiers in R
Numerical Constants
Character Constants
Constants: Built-in Constants
BASIC OPERATIONS IN R
<-
R Is Case-Sensitive
Function
Defined in Base R
R OPERATORS
Types of Operators
R ARITHMETIC OPERATORS
MATRIX OPERATIONS IN R
Addition and Subtraction
TRANSPOSE A MATRIX IN R
Matrix Multiplication in R
Multiplication by a Scalar
Element-Wise Multiplication
Matrix Multiplication in R
Matrix Multiplication Using Three Matrix
MATRIX CROSS-PRODUCT
Exterior Product
Kronecker Product
POWER OF A MATRIX IN R
Determinant of a Matrix in R
Inverse of a Matrix in R
Rank of a Matrix in R
R RELATIONAL OPERATORS
Less Than (<) and Greater Than (<)
Greater Than (>)
Less Than Equal (<=)
Greater Than Equal (>=)
Not Equal to (!=)
Assignment Operators
R LOGICAL OPERATORS
AND Operator “&”
R Miscellaneous Operators
CHAPTER SUMMARY
NOTES
CHAPTER 4: Loops and Decision-Making in R
CONTROL STRUCTURES IN R PROGRAMMING
If Statement in R
NESTED IF STATEMENTS
If–Else Statement
Nested If–Else Statements
R If–Else–If Statement
R Switch Statement
R Repeat Statement
Next Statement
Return Statement
Break Statement
LOOPING IN R
R ifelse() Function
CHAPTER SUMMARY
NOTES
CHAPTER 5: Functions and Strings
INTRODUCTION
Defining a Function
Functional Components
Arguments
Number of Arguments
Default Parameter Value
FUNCTION TYPES
Primitive Function
Infix Functions
INFIX OPERATORS IN R
USER-DEFINED INFIX OPERATOR
THE gR GLOBAL VARIABLES
THE GLOBAL ASSIGNMENT OPERATOR
TYPES OF FUNCTIONS
Function Call
BUILT-IN FUNCTIONS
Numeric Functions
Character Functions
Statistical Probability Functions
Other Statistical Functions
R STRINGS
String Basics
c() Function in R
BUILT-IN STRING FUNCTION IN R
String Manipulation
CHAPTER SUMMARY
NOTES
CHAPTER 6: Lists and Arrays
INTRODUCTION
LIST OPERATIONS
Creating a List
Naming List Elements in R
Access to R List Elements
INDEXING LISTS
SLICING THE LIST
Letters
LETTERS
month.abb
month.name
ADDING, DELETING, AND UPDATING ELEMENTS OF A LIST
CONVERTING A LIST TO VECTOR
DOUBLE VERSUS SINGLE PARENTHESES
LIST LENGTH
Check If Item Exists
ADD LIST IN ITEMS
REMOVE LIST ITEMS
RANGE OF INDEXES IN LIST
LOOP THROUGH A LIST
Join Two Lists
CHAPTER SUMMARY
NOTES
CHAPTER 7: Data Structures
INTRODUCTION
VECTOR
Single Element Vector
How to Create Vector in R?
Atomic Vectors
Types of Vectors
Numeric Vectors
Character Vectors
Logical Vectors
CREATION OF VECTOR IN R
Create Vector Using c() Function
Create Vector Using seq() Function
Create Vector Using: Operator
R MATRIX
Creating a Matrix in R
Access Elements of a Matrix
DATA FRAME
CHAPTER SUMMARY
NOTES
CHAPTER 8: Error Handling and File Handling
INTRODUCTION
Warning
Message
HANDLING ERROR FUNCTIONS
MANIPULATION OF CONDITIONS IN R
withCallingHandlers() in R
PROCESSING CONDITIONS IN R PROGRAMMING
CHANGING OF CONDITIONS PROGRAMMATICALLY
Custom Signal Classes
DEBUGGING IN R PROGRAMMING
Editor Breakpoints
The traceback()
browser() Function
recover() Function
DEBUGGING TOOLS IN R
Using debug()
Using recover()
FILE HANDLING IN R
Creation of a File
Writing to Files
Parameters
Reading Data from a File
Parameters
Check an Existing File
CHAPTER SUMMARY
NOTES
CHAPTER 9: Graphics in R
INTRODUCTION GRAPHIC
Types of R Charts
DATA SET
Information-Related Data Set
Get Information
Print Variable Values
Sort Variable Values
Analyzing the Data
Max Min
Mean, Median, and Mode
Mean
Median
Mode
Visualize the mtcars Data Set
To Create a Scatter Plot
Loading the mtcars Data Set in R Code
BAR CHART
Syntax
R PLOTTING
R PLOT TYPE
R PLOT PCH
Plot Title in R
SUBTITLE IN R PLOT
AXIS IN R
R LINE CHART AND GRAPH
ADDING TITLE, COLOR, AND LABELS TO LINE CHARTS IN R
MULTIPLE LINES IN A LINE CHART
Color
Width
Style
MULTIPLE LINES
R SCATTER PLOT
Creating the Scatterplot
Scatter Matrices
PIE CHARTS
Pie Chart Title and Colors
3D Pie Chart
Pie Chart Height in R
Pie Chart Angle in R
BOXPLOT
Histograms and Density Plots in R
Parameters
Density Plot
HEATMAP
Using the Heatmap()
PARIS PLOT
VENN DIAGRAM
CHAPTER SUMMARY
NOTES
APPRAISAL
INDEX