R Programming - PPT - UNIT- 1
R Programming - PPT - UNIT- 1
SCIENCE
UNIT- 1
INTRODUCTION
• The R Language stands out as a powerful tool
in the modern era of statistical computing and
data analysis. Widely embraced by
statisticians, data scientists, and researchers
R Programming
• R programming is a leading tool for
• Machine Learning,
• Statistics, and
• Data Analysis,
allowing for the easy creation of objects,
functions, and packages.
Why WeUse R Language
cos(), sin(), and tan() calculates a number’s cosine, sine, and tang.
• Types of Function in R Language
– Built-in Function: are pre-defined functions -
to perform common tasks or operations
– functions like sum(), max() and min().
– User-defined Function: R language allow us to
write our own function
CRAN
• CRAN abbreviates Comprehensive R Archive Network will
provide binary files and follow the installation
• instructions and accepting all defaults. Download from http://cran.r-
project.org/ we can see the R Console window
• will be in the RGui (graphical user interface).
• Create a new R script file:
• To create a new R script file:
• 1) File -> New -> R Script,
• 2) Click on the icon with the “+” sign and select “R Script”
• 3) Use shortcut as: Ctrl+Shift+N.
• Running the R commands on R Script file:
• First R program: Using R as calculator:
• R commands can run in two ways:
• 1) Type at console and press enter to see the output. Output will
get at console only in R studio.
• 2) Open new R Script file and write the command, keep the curser
on the same line and press Ctrl+enter or click
• on Run. Then see the output at console along with command.
• At console:
• R as a calculator, typing commands directly into the R Console.
Launch R and type the following code, pressing
• < Enter > after each command.
• Type an expression on console.
• R - Assignment Operators:
• <- or = for assignment and == to test equality.
• At the outer sider <- and = can be used similar. But we should be
careful while using them in combined. In
• precise ‘<-’ is prioritized than ‘=’ . The operators <- and = assign
into the environment in which they are
• evaluated. The operator <- can be used anywhere, whereas the
operator = is only allowed at the top level (e.g.,
• in the complete expression typed at the command prompt) or as
one of the subexpressions in a braced list of
• expressions.
• x <- y <- 5
• x = y = 5
• x = y <- 5
• x <- y = 5
• # Error in (x <- y) = 5 : could
not find function "<-<-"
• Example Exercise1:
• > 2 * 2 ## Multiplication
• [1] 4
• > 2 / 2 ## Division
• [1] 1
• > 2 + 2 ## addition
• [1] 4
• > 2 – 2 ## subtraction
• [1] 0
• > 2 ^ 2 ## exponentiation
• [1] 4
• > q() ## to quit
• > y <- 3*exp(x)
• > x <- 3*exp(x)
• R expression:
• At ‘>’ (R-prompt) type the R expression and press enter
• R output:
• R labels each output value with a number in square brackets. As
far as R is concerned, an individual number is a
• one-element vector. The [1] is simply the index of the first element
of the vector.
• Activity1: Calculate the following using R:
• 1. Log of 2
• 2.23 X 32
• 3. e3
Variable (Object) Names: