Data Science with R
Unit II: R PROGRAMMING STRUCTURES
M Narasimha Raju
Dept. of Computer Science & Engineering
Shri Vishnu Engineering College for Women (A),
Bhimavaram
⚫Decision making structures require the programmer to
specify one or more conditions to be evaluated or tested by
the program, along with a statement or statements to be
executed if the condition is determined to be true, and
optionally, other statements to be executed if the condition is
determined to be false.
2
if
3
R – If...Else Statement
4
The if...else if...else Statement
5
R – Switch Statement
6
7
Repeat Loop
⚫The Repeat loop executes the same code again and again until
a stop condition is met.
8
While Loop
9
For Loop
10
11
break
12
next
13
⚫7.1 Control Statements
⚫Loops
14
⚫if-else
15
7.
2
Arithmetic and Boolean Operators and Values
16
Return Values
⚫Functions Are Objects
17
Environment and Scope Issues
⚫The Top-Level Environment
⚫The Scope Hierarchy
18
Tools for Composing Function Code
⚫Text Editors and Integrated Development Environments
⚫We can use a text editor such as Vim, Emacs, or even Notepad,
or an editor within an integrated development environment
(IDE) to write your code in a file and then read it into R from the
file.
⚫The edit() Function
⚫R programmers do their code editing with a text editor in a
separate window, but for a small, quick change, the edit()
function can be handy.
19
Thank
You
M Narasimha Raju
Dept. of Computer Science & Engineering
Shri Vishnu Engineering College for Women (A),
Bhimavaram