Chapter 1 Introduction To R
Chapter 1 Introduction To R
CHAPTER 1
INTRODUCTION TO R PROGRAMMING
What is R programming?
3) Click Next..Next..Finish.
4)Download Complete.
DSC551 (PROGRAMMING FOR DATA SCIENCE)
Features of R Studio
R SCRIPT R CONSOLE
GRAPHICAL PLOT
R ENVIRONMENT
DSC551 (PROGRAMMING FOR DATA SCIENCE)
R SCRIPT R CONSOLE
Why Learn R?
Availability and
open source
tool
Widely used for
statistical data It is very flexible
analysis, data and highly
manipulation, data customizable.
mining and machine
learning.
Has a large
community
users
DSC551 (PROGRAMMING FOR DATA SCIENCE)
Application of R?
Fraud Weather
detection Forecasting
Record Keeping
DSC551 (PROGRAMMING FOR DATA SCIENCE)
Eg: install.packages(“MASS”)
DSC551 (PROGRAMMING FOR DATA SCIENCE)
1
2) Type package name in the search field and check (/) in the box
TYPE HERE 2
1 3
2
DSC551 (PROGRAMMING FOR DATA SCIENCE)
Type of Data/Object in R
Data Types Description Example
Also known as boolean data type TRUE and FALSE
Logical
Type of Operators in R
• + • < • ! • Left
• - • > • & assignment:
• / • <= • && <-, =, <<-
• * • >= • | • Right
assignment:
• ^ • == • ||
-> , ->>
• %% • !=
• %/%
DSC551 (PROGRAMMING FOR DATA SCIENCE)
Assignment
Arithmetic Given x=10 and y=2,complete the following output in the following table:
+ Addition x+y
- Subtraction x-y
* Multiplication x*y
/ Division y/x
^ Exponentiation x^y
Relational Given x=5 and y=16,complete the following output in the following table:
== Equal to x==y
| Logical OR k|m
Exercises
a) Install “fBasics” package in R/ R studio.
b) List TWO (2) types of data/object. Provide example for each of the types of data/object listed.
c) State TWO (2) advantages of R programming language.
d) Write the following expression in R.
e) Name the built-in functions used to tabulate/summarize the data according to classes/groups.
f) Given that the circumference of a cake is, c= 11.3563 cm. Use this information to answer the
following questions:
i. c1=round(c,2)
ii. floor(c1)
iii. ceiling(c1)