0% found this document useful (0 votes)
28 views

R Programming - PPT - UNIT- 1

The document provides an overview of R programming, highlighting its significance in statistical computing and data analysis. It discusses the advantages and disadvantages of R, its features, applications, and the installation process, along with basic functions and operators. Additionally, it covers the use of packages, workspace management, and the R environment for effective programming.

Uploaded by

thangam suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

R Programming - PPT - UNIT- 1

The document provides an overview of R programming, highlighting its significance in statistical computing and data analysis. It discusses the advantages and disadvantages of R, its features, applications, and the installation process, along with basic functions and operators. Additionally, it covers the use of packages, workspace management, and the R environment for effective programming.

Uploaded by

thangam suresh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 72

R PROGRAMMING FOR DATA

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

1. Comprehensive Statistical Analysis:


R language is specifically designed for statistical analysis and provides a vast
array of statistical techniques and tests, making it ideal for data-driven research.
2. Extensive Packages and Libraries:
The R Language boasts a rich ecosystem of packages and libraries that extend its
capabilities, allowing users to perform advanced data manipulation,
visualization, and machine learning tasks with ease.
3. Strong Data Visualization Capabilities:
R language excels in data visualization, offering powerful tools like ggplot2 and
plotly, which enable the creation of detailed and aesthetically pleasing graphs
and plots.
4. Open Source and Free:
As an open-source language, R is free to use, which makes it accessible to
everyone, from individual researchers to large organizations, without the need
for costly licenses.
5. Platform Independence:
The R Language is platform-independent, meaning it can run on various operating
systems, including Windows, macOS, and Linux, providing flexibility in development
environments.
6. Integration with Other Languages:
R can easily integrate with other programming languages such as C, C++, Python, and
Java, allowing for seamless interaction with different data sources and statistical
packages.
7. Growing Community and Support:
R language has a large and active community of users and developers who contribute
to its continuous improvement and provide extensive support through forums,
mailing lists, and online resources.
8. High Demand in Data Science:
R is one of the most requested programming languages in the Data Science job
market, making it a valuable skill for professionals looking to advance their careers in
this field.
Features of R Programming Language

• Comprehensive Statistical Analysis


• Advanced Data Visualization
• Extensive Packages and Libraries
• Open Source and Free
• Platform Independence
• Integration with Other Languages
• Powerful Data Handling and Storage
• Robust Community and Support
• Interactive Development Environment (IDE)
• Reproducible Research
Advantages of R language

• R is the most comprehensive statistical analysis


package. As new technology and concepts often
appear first in R.
• As R programming language is an open source. We can
run R anywhere and at any time.
• It is suitable for GNU/Linux and Windows operating
systems.
• It is cross-platform and runs on any operating system.
• In R, everyone is welcome to provide new packages,
bug fixes, and code enhancements.
Disadvantages of R language

• The standard of some packages is less than


perfect.
• R programming language may consume all
available memory.
• Nobody to complain if something doesn’t
work.
• It is much slower than other programming
languages such as Python and MATLAB
Applications of R language

• We use R for Data Science. It gives us a broad variety of


libraries related to statistics. It also provides the
environment for statistical computing and design.
• R is used by many quantitative analysts as its
programming tool. Thus, it helps in data importing and
cleaning.
• R is the most prevalent language. So many data analysts
and research programmers use it. Hence, it is used as a
fundamental tool for finance.
• Tech giants like Google, Facebook, Bing, Twitter,
Accenture, Wipro, and many more using R nowadays.
Install R and RStudio
Function Name Example
abs absolute value abs(3-6) = 3
sqrt square root sqrt(16) = 4
^ Exponentiation 3^10 = 310310 = 59049
exp exponential function exp(1.7) = e1.7e1.7 = 5.473947
log log function (base e) log(10) = 2.302585
log10 base 10 log (log10log10) log10(100) = 2
pi mathematical constant ππ pi = 3.141593
sin, cos, tan trigonometric functions sin(pi/2) = 1
(argument in radians)
asin, acos, inverse trigonometric functions acos(1) = 0
atan
sinh, cosh, hyperbolic functions cosh(0) = 1
tanh
asinh, acosh, inverse hyperbolic functions atanh(tanh(12)) = 12
atanh
round(x,n) round x to n decimal places round(pi,2) = 3.14
floor rounds down floor(14.7) = 14
ceiling rounds up ceiling(14.7) = 15
PACKAGES
The R installation comes with a set of basic
packages.
Thousands of packages for various analysis are
kept at external repositories.
These external packages can be downloaded
from R prompt via internet.
The downloaded package will be placed inside a
directory inside R the installation.
• From R prompt, the command
• > .libPaths()
– will list the directories where the downloaded
packages are installed.
– To get a list and small description of all the R
packages installed in the system, call
the list() function:
> list()
• To install an external R
package, use install.packages() function
• For example, to install the package called cluster , type:
• install.packages("cluster")

• The package can be included in a R script by


calling library() function with package name as a string
argument:
• > library("cluster")
• The data sets inside a package can be listed by data() function:
• > data(package="cluster")

• A package attached by the library() can be removed by


the detach() function:
• > detach("package:cluster")

• To display all the packages available in the repositories,


• > new.packages()

• In order to update all the installed packages with the newest


version from repositories,
• > update.packages()
• The workspace is your current R working
environment and includes any user-defined
objects (vectors, matrices, data frames, lists,
functions).
• getwd() # print the current working directory -
cwd
• ls() # list the objects in the current workspace
• setwd(mydirectory) # change to mydirectory
• setwd("c:/docs/mydir") # note / instead of \ in
windows
• setwd("/usr/rob/mydir") # on linux
• help(options) # learn about available options
• options() # view current option settings
• options(digits=3) # number of digits to print
on output
• # work with your previous commands
• history() # display last 25 commands
• history(max.show=Inf) # display all previous
commands
• # save your command history
• savehistory(file="myfile") # default is ".Rhistory"

• # recall your command history
• loadhistory(file="myfile")
• # default is ".Rhistory"

• # save the workspace to the file .RData in the cwd
• save.image()
• # save specific objects to a file
• # if you don't specify the path, the cwd is assumed
• save(object list,file="myfile.RData")

• # load a workspace into the current session


• # if you don't specify the path, the cwd is assumed
• load("myfile.RData")
• q() # quit R. You will be prompted to save the
workspace
abs() calculates a number’s absolute value.

sqrt() calculates a number’s square root.

round() rounds a number to the nearest integer.

exp() calculates a number’s exponential value

which calculates a number’s natural


log()
logarithm.

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:

• Certain variable names are reserved for particular purposes. Some


reserved symbols are: c q t C D F I T
• ### meaning of c q t C D F I T
• ? ## to see help document
• ?c ## c means Combine Values into a Vector or List
• ?q ## q means Terminate an R Session
• ?t ## t means Matrix Transpose
• ?C ## C means sets contrast for a factor
• ?D ## D means Symbolic and Algorithmic Derivatives of Simple
Expressions
• ?F ## F means logical vector Character strings
• c("T", "TRUE", "True", "true") are regarded as true, c("F", "FALSE",
"False", "false") as false, and all others as
• NA.
• >F ##[1] FALSE
• ?I ##Inhibit Interpretation/Conversion of Objects
Operators in R:
• Comment Notation in R:
• # is used to comment a line in R script.
• List of Objects:
• To see a listing of the objects in your workspace, you can use the
ls() function. To get more detail, use ls.str()
• > ls()
• [1] "A" "acctdata" "address" "B" "b1"
• [6] "balance" "c" "CareerSat" "chisquare" "colnames"

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy