D1 R-Intro
D1 R-Intro
01 02 03
SESSION SET-UP WHY R GETTING R
R popularity, R vs. others, R How to install, R & RStudio, How to
What to expect, session
capacities, pros and cons run R programs,
objectives, planned activities
04 05 06
INTRO TO CORE R SELF LEARNING END OF DAY
FEATURES EXERCISE
How to keep learning R on your own
Key language features
SESSION OBJECTIVES Expected Learning Outcomes
05 HANDLE FILES
Read from files, write to files and use module to retrieve files
4 hrs. 2 hrs.
5
WHY R?
Easy to lean
Who Uses R?
Some of the Well Known Companies Who Use R
4. Easy to learn
User community
Sharing of code
Technical support
Machine Learning
Large and
unstructured data
Key R Features
How easy is R?
Portable
Supported by many platforms like Linux, Windows,
FreeBSD, Macintosh Python
How to Get and Install R
Install essential Use R
Install R for your OS
Libraries/Packages
Rstudio can be installed with either R 4.2 or 3. We will use R 4.3. in this course.
R Development ENvironments
Development Environment: a place where you write and/or run R program
3. Rstudio /R Notebook
4. Jupyter Notebook
HELLO WORLD!
R first program in different coding environments.
R Program Environments
1. Basic Terminal
print(“Hello World”)
2. Sypder (similar to R studio)
3. Rstudio /R Notebook
4. Jupyter Notebook
15
Console
Install
Packages/Vi
sualization
What is RStudio?
A graphical interface application in which you can create and share documents that contain live
codes, equations, visualizations and text.
Basic Features
• The RStudio application produces documents that we
call "scripts", "R Notebooks" or "R markdown
documents", which contain both code and rich text
elements, such as figures, links, equations, etc.
• Cells:
• Creating, inserting, deleting and moving cells
• Execute a cell, stop execution, execute many cells, etc
• Code cells vs text cells
• Knowing when a cell is executing
• Kernels
• Interrupt/stop/restart/shutdown kernel
• Change kernel
• Tips
• Getting help
• Tab completion
• Shortcuts
Exercise: Familiarize Yourself with the Rstudio
Time: 5 minutes
1. Launch RStudio
01 OPERATORS
Assignment, arithmetic and more
03 CONTROL FLOW
Conditional statements, and loops
05 FILE HANDLING
Reading, writing files, using the module
R Operators
SUBTRACTION (-)
Subtracts two operands
MULTIPLICATION (*)
Multiplies two operands
DIVISION (/)
Divide left operand with the right and result is
in numeric
EXPONENTION (**)
Left operand raised to the power of
right
REMAINDER (%%)
Remainder of the division of the left operand by the right
Assignment Operators
• Assignment uses =
Comparison Operators
Operator Exemple
GREATER (>)
True if left operand is greater than right
EQUAL TO (==)
Tue if left operand is equal
to right
NOT EQUAL TO ( !=)
True if left operand is not equal
to right
Logical Operators
Operators & and | have expected definitions
&
If both the operands are true then
condition becomes true.
|
True if left operand is less than right.
27
R Data Types
Data Type
Immutable Mutable
• How to use them with data science libraries (e.g., readxl) [Lists, dicts, data
frame, arrays, etc.]
Although R does some data type conversion internally (e.g., converts numbers from
strings) sometimes, you need to coerce a data type explicitly from one type to another
to satisfy the requirements of an operator or function parameter.
Numbers in R
Number data types store numeric values. They are immutable data types, means that changing
the value of a number data type results in a newly allocated object.