SlideShare a Scribd company logo
Introduction to R
Venkat Reddy
•
•
•
•
•
•
•
•

What is R
R basics
Working with R
R packages
R Functions
Importing & Exporting data
Creating calculated fields
R Help & Tutorials

Data Analysis Course
Venkat Reddy

Contents

2
• Programming “environment”
• Runs on a variety of platforms including Windows, Unix and
MacOS.
• Provides an unparalleled platform for programming new
statistical methods in an easy and straightforward manner.
• Object-oriented
• Open source
• Excellent graphics capabilities
• Supported by a large user network

Data Analysis Course
Venkat Reddy

R

3
Downloading

Data Analysis Course
Venkat Reddy

• Google it using R or CRAN (Comprehensive R Archive
Network)
• http://www.r-project.org

4
Data Analysis Course
Venkat Reddy

R

5
Data Analysis Course
Venkat Reddy

R Studio

6
•
•
•
•
•

2+2
log(10)
help(log)
summary(airquality)
demo(graphics) # pretty pictures...

Data Analysis Course
Venkat Reddy

R-Demo

7
R-Basics :Naming convention
• must start with a letter (A-Z or a-z)
• can contain letters, digits (0-9), and/or periods “.”
• mydata different from MyData

Data Analysis Course
Venkat Reddy

• R is a case sensitive language.

8
R-Basics :Assignment
• “<-” used to indicate assignment

• Assignment to an object is denoted by ”<-” or ”->” or ”=”.
• If you see a notation ”= =”, you’ll looking at a comparison
operator.
– Many other notations can be found from the
documentation for the Base package or R.

Data Analysis Course
Venkat Reddy

• x<-c(1,2,3,4,5,6,7)
• x<-c(1:7)
• x<-1:4

9
• during an R session, all objects are stored in a
temporary, working memory
• Commands are entered interactively at the R user prompt. Up
and down arrow keys scroll through your command history.
• list objects ls()
• remove objects rm()
• data()

Data Analysis Course
Venkat Reddy

Workspace

10
•
•
•
•
•
•
•
•
•
•

x <- round(rnorm(10,mean=20,sd=5)) # simulate data
x
mean(x)
m <- mean(x)
m
x- m # notice recycling
(x - m)^2
sum((x - m)^2)
data()
UKgas

Data Analysis Course
Venkat Reddy

Demo: Working with R

11
• R consists of a core and packages. Packages contain functions
that are not available in the core.
• Collections of R functions, data, and compiled code
• Well-defined format that ensures easy installation, a basic
standard of documentation, and enhances portability and
reliability
• When you download R, already a number (around 30) of
packages are downloaded as well.
• You can use the function search to see a list of packages that
are currently attached to the system, this list is also called the
search path.

• search()

Data Analysis Course
Venkat Reddy

R Packages

12
• Select the `Packages' menu and select `Install package...', a list
of available packages on your system will be displayed.
• Select one and click `OK', the package is now attached to your
current R session. Via the library function
• The library can also be used to list all the available libraries on
your system with a short description. Run the function
without any arguments

Data Analysis Course
Venkat Reddy

R packages

13
Demo: R packages

Data Analysis Course
Venkat Reddy

• Install cluster package
• Install plyr package (for string operations)

14
Importing Data
• Reading CSV file
• X <-read.csv(“file.csv")

• reads in data from an external file
• d <- read.table("myfile", header=TRUE)

• R has ODBC for connecting to other programs
• R gets confused if you use a path in your code like
c:mydocumentsmyfile.txt
• This is because R sees "" as an escape character. Instead, use
c:my documentsmyfile.txt
or
c:/mydocuments/myfile.txt

Data Analysis Course
Venkat Reddy

• read.table()

15
Demo: Importing data
• petrol<-read.csv("C:UsersVENKATGoogle
DriveTrainingRDataPetrol_Consuption.csv")
• sales_data<-read.table("C:UsersVENKATGoogle
DriveTrainingRDatasales.txt")
• sales_data<-read.table("C:UsersVENKATGoogle
DriveTrainingRDatasales.txt",header=TRUE)

Data Analysis Course
Venkat Reddy

• Reading CSV file

16
Exporting data
• To A Tab Delimited Text File
• write.table(mydata, "c:/mydata.txt", sep="t")
• library(xlsReadWrite)
• write.xls(mydata, "c:/mydata.xls")

• To SAS
• library(foreign)
• write.foreign(mydata, "c:/mydata.txt", "c:/mydata.sas", package="SAS")

Data Analysis Course
Venkat Reddy

• To an Excel Spreadsheet

17
Demo: Exporting data

Data Analysis Course
Venkat Reddy

• write.table(sales_data, "C:UsersVENKATGoogle
DriveTrainingRDatasales_export.txt", sep="t")
• write.table(sales_data, "C:UsersVENKATGoogle
DriveTrainingRDatasales_export.csv", sep=",")

18
R- Functions
Numeric Functions
Description

abs(x)

absolute value

sqrt(x)

square root

ceiling(x)

ceiling(3.475) is 4

floor(x)

floor(3.475) is 3

trunc(x)

trunc(5.99) is 5

round(x, digits=n)

round(3.475, digits=2) is 3.48

signif(x, digits=n)

signif(3.475, digits=2) is 3.5

cos(x), sin(x), tan(x)

also acos(x), cosh(x), acosh(x), etc.

log(x)

natural logarithm

log10(x)

common logarithm

exp(x)

e^x

Data Analysis Course
Venkat Reddy

Function

19
•
•
•
•

y<-abs(-20)
x<-Sum(y+5)
Z<-Log(x)
round(x,1)

Data Analysis Course
Venkat Reddy

Demo: Numeric Functions

20
Character Functions
Description

substr(x, start=n1, stop=n2)

Extract or replace substrings in a character vector.
x <- "abcdef"
substr(x, 2, 4) is "bcd"
substr(x, 2, 4) <- "22222" is "a222ef"

grep(pattern, x ,
ignore.case=FALSE,
fixed=FALSE)

Search for pattern in x. If fixed =FALSE then pattern is a regular
expression. If fixed=TRUE then pattern is a text string. Returns
matching indices.
grep("A", c("b","A","c"), fixed=TRUE) returns 2

sub(pattern, replacement, x,
ignore.case =FALSE,
fixed=FALSE)

Find pattern in x and replace with replacement text. If fixed=FALSE
then pattern is a regular expression.
If fixed = T then pattern is a text string.
sub("s",".","Hello There") returns "Hello.There"

strsplit(x, split)

Split the elements of character vector x at split.
strsplit("abc", "") returns 3 element vector "a","b","c"

paste(..., sep="")

Concatenate strings after using sep string to seperate them.
paste("x",1:3,sep="") returns c("x1","x2" "x3")
paste("x",1:3,sep="M") returns c("xM1","xM2" "xM3")
paste("Today is", date())

toupper(x)

Uppercase

Data Analysis Course
Venkat Reddy

Function

21
Demo :Character Functions

Data Analysis Course
Venkat Reddy

• cust_id<-"Cust1233416"
• id<-substr(cust_id, 5,10)
• Up=toupper(cust_id)

22
Calculated Fields in R
•
•
•
•
•
•

mydata$sum <- mydata$x1 + mydata$x2
mydata$mean <- (mydata$x1 + mydata$x2)/2
attach(mydata)
mydata$sum <- x1 + x2
mydata$mean <- (x1 + x2)/2
detach(mydata)

Data Analysis Course
Venkat Reddy

• Use the assignment operator <- to create new variables. A
wide array of operators and functions are available here.

23
•
•
•
•
•
•
•
•

sales_data$reduce<-(sales_data$Sales)*0.2
View(sales_data)
sales_data$new_sales<-sales_data$Sales- sales_data$reduce
attach(petrol)
ratio=Income/consum_mill_gallons
View(petrol)
petrol$ratio=Income/Consum_mill_gallons
View(petrol)

Data Analysis Course
Venkat Reddy

Demo Calculated Fields in R

24
• If you encounter a new command during the exercises, and you’d
like to know what it does, please consult the documentation. All R
commands are listed nowhere, and the only way to get to know new
commands is to read the documentation files, so we’d like you to
practise this youself.
• Tutorials
Each of the following tutorials are in PDF format.
• P. Kuhnert & B. Venables, An Introduction to R: Software for Statistical
Modeling & Computing
• J.H. Maindonald, Using R for Data Analysis and Graphics
• B. Muenchen, R for SAS and SPSS Users
• W.J. Owen, The R Guide
• D. Rossiter, Introduction to the R Project for Statistical Computing for
Use at the ITC
• W.N. Venebles & D. M. Smith, An Introduction to R

Data Analysis Course
Venkat Reddy

R-Help

25
R-Tutorials
Paul Geissler's excellent R tutorial
Dave Robert's Excellent Labs on Ecological Analysis
Excellent Tutorials by David Rossitier
Excellent tutorial an nearly every aspect of R (c/o Rob
Kabacoff) MOST of these notes follow this web page format
• Introduction to R by Vincent Zoonekynd
• R Cookbook
• Data Manipulation Reference

Data Analysis Course
Venkat Reddy

•
•
•
•

26
Data Analysis Course
Venkat Reddy

Thank you

27

More Related Content

What's hot (20)

PDF
Data structures and algorithm analysis in java
Muhammad Aleem Siddiqui
 
PPTX
Session 06 machine learning.pptx
bodaceacat
 
PDF
Introduction of Feature Hashing
Wush Wu
 
PPTX
Analysis of algorithms
iqbalphy1
 
PDF
QBIC
Misha Kozik
 
PDF
Generalized Linear Models with H2O
Sri Ambati
 
PPTX
K-means Clustering with Scikit-Learn
Sarah Guido
 
PPTX
Data Structure and Algorithms
iqbalphy1
 
PDF
Introduction data structure
MUHAMMAD ISMAIL
 
PDF
Feature Engineering - Getting most out of data for predictive models
Gabriel Moreira
 
PPT
Chapter15
gourab87
 
PDF
Enhancing Spark SQL Optimizer with Reliable Statistics
Jen Aman
 
PDF
Log Analytics in Datacenter with Apache Spark and Machine Learning
Piotr Tylenda
 
PPTX
Ppt shuai
Xiang Zhang
 
PPT
Query compiler
Digvijay Singh
 
PPTX
Branch And Bound and Beam Search Feature Selection Algorithms
Chamin Nalinda Loku Gam Hewage
 
PDF
Building Random Forest at Scale
Sri Ambati
 
PDF
Random forest using apache mahout
Gaurav Kasliwal
 
PDF
Kaggle Higgs Boson Machine Learning Challenge
Bernard Ong
 
PPTX
Ml7 bagging
ankit_ppt
 
Data structures and algorithm analysis in java
Muhammad Aleem Siddiqui
 
Session 06 machine learning.pptx
bodaceacat
 
Introduction of Feature Hashing
Wush Wu
 
Analysis of algorithms
iqbalphy1
 
Generalized Linear Models with H2O
Sri Ambati
 
K-means Clustering with Scikit-Learn
Sarah Guido
 
Data Structure and Algorithms
iqbalphy1
 
Introduction data structure
MUHAMMAD ISMAIL
 
Feature Engineering - Getting most out of data for predictive models
Gabriel Moreira
 
Chapter15
gourab87
 
Enhancing Spark SQL Optimizer with Reliable Statistics
Jen Aman
 
Log Analytics in Datacenter with Apache Spark and Machine Learning
Piotr Tylenda
 
Ppt shuai
Xiang Zhang
 
Query compiler
Digvijay Singh
 
Branch And Bound and Beam Search Feature Selection Algorithms
Chamin Nalinda Loku Gam Hewage
 
Building Random Forest at Scale
Sri Ambati
 
Random forest using apache mahout
Gaurav Kasliwal
 
Kaggle Higgs Boson Machine Learning Challenge
Bernard Ong
 
Ml7 bagging
ankit_ppt
 

Viewers also liked (20)

PPTX
Decision tree
Venkata Reddy Konasani
 
PPTX
Introduction to predictive modeling v1
Venkata Reddy Konasani
 
PPTX
Credit Risk Model Building Steps
Venkata Reddy Konasani
 
PPTX
Testing of hypothesis case study
Venkata Reddy Konasani
 
PDF
Model building in credit card and loan approval
Venkata Reddy Konasani
 
PPT
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced features
Venkata Reddy Konasani
 
PDF
Machine Learning for Dummies
Venkata Reddy Konasani
 
PPTX
Estadística con Lenguaje R: Sesión 2
Luis Fernando Aguas Bucheli
 
PPTX
Estadística con Lenguaje R: Sesión 3
Luis Fernando Aguas Bucheli
 
PPTX
Estadística con Lenguaje R: Sesión 1
Luis Fernando Aguas Bucheli
 
PDF
Transformación digital en cifras
Creando ideas - Inbound Marketing
 
PPTX
Estadística con Lenguaje R: Sesión 7
Luis Fernando Aguas Bucheli
 
PPTX
Estadística con Lenguaje R: Sesión 5
Luis Fernando Aguas Bucheli
 
PPTX
Current Expected Credit Loss Model Presentation
Kristina Caltagirone
 
PPT
Application layer chapter-9
Student
 
PPTX
Estadística con Lenguaje R: Sesión 4
Luis Fernando Aguas Bucheli
 
PPTX
Estadística con Lenguaje R: Sesión 8
Luis Fernando Aguas Bucheli
 
PDF
¿Qué debemos hacer desde Tecnología para estar alineados con la Transformac...
Martín Cabrera
 
PDF
Transformación digital y el nuevo paradigma de TI
Software Guru
 
PPT
Understanding and Predicting Ultimate Loss-Given-Default on Bonds and Loans
Michael Jacobs, Jr.
 
Decision tree
Venkata Reddy Konasani
 
Introduction to predictive modeling v1
Venkata Reddy Konasani
 
Credit Risk Model Building Steps
Venkata Reddy Konasani
 
Testing of hypothesis case study
Venkata Reddy Konasani
 
Model building in credit card and loan approval
Venkata Reddy Konasani
 
Learning Tableau - Data, Graphs, Filters, Dashboards and Advanced features
Venkata Reddy Konasani
 
Machine Learning for Dummies
Venkata Reddy Konasani
 
Estadística con Lenguaje R: Sesión 2
Luis Fernando Aguas Bucheli
 
Estadística con Lenguaje R: Sesión 3
Luis Fernando Aguas Bucheli
 
Estadística con Lenguaje R: Sesión 1
Luis Fernando Aguas Bucheli
 
Transformación digital en cifras
Creando ideas - Inbound Marketing
 
Estadística con Lenguaje R: Sesión 7
Luis Fernando Aguas Bucheli
 
Estadística con Lenguaje R: Sesión 5
Luis Fernando Aguas Bucheli
 
Current Expected Credit Loss Model Presentation
Kristina Caltagirone
 
Application layer chapter-9
Student
 
Estadística con Lenguaje R: Sesión 4
Luis Fernando Aguas Bucheli
 
Estadística con Lenguaje R: Sesión 8
Luis Fernando Aguas Bucheli
 
¿Qué debemos hacer desde Tecnología para estar alineados con la Transformac...
Martín Cabrera
 
Transformación digital y el nuevo paradigma de TI
Software Guru
 
Understanding and Predicting Ultimate Loss-Given-Default on Bonds and Loans
Michael Jacobs, Jr.
 
Ad

Similar to R- Introduction (20)

PPT
Basics of R-Progranmming with instata.ppt
geethar79
 
PPT
17641.ppt
AhmedAbdalla903058
 
PPT
Slides on introduction to R by ArinBasu MD
SonaCharles2
 
PPT
17641.ppt
vikassingh569137
 
PPT
Introduction to R for Data Science Technology
gufranqureshi506
 
PPTX
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
PPT
How to obtain and install R.ppt
rajalakshmi5921
 
PPT
Modeling in R Programming Language for Beginers.ppt
anshikagoel52
 
PPT
Lecture1_R.ppt
vikassingh569137
 
PPT
Lecture1_R.ppt
ArchishaKhandareSS20
 
PPT
Lecture1 r
Sandeep242951
 
PDF
Lecture1_R.pdf
BusyBird2
 
PPT
Lecture1_R Programming Introduction1.ppt
premak23
 
PDF
R-Language-Lab-Manual-lab-1.pdf
KabilaArun
 
PDF
R-Language-Lab-Manual-lab-1.pdf
attalurilalitha
 
PDF
R-Language-Lab-Manual-lab-1.pdf
DrGSakthiGovindaraju
 
PPT
Advanced Data Analytics with R Programming.ppt
Anshika865276
 
PPT
Brief introduction to R Lecturenotes1_R .ppt
geethar79
 
PPT
R_Language_study_forstudents_R_Material.ppt
Suresh Babu
 
PDF
Introduction+to+R.pdf
MudasserAziz2
 
Basics of R-Progranmming with instata.ppt
geethar79
 
Slides on introduction to R by ArinBasu MD
SonaCharles2
 
17641.ppt
vikassingh569137
 
Introduction to R for Data Science Technology
gufranqureshi506
 
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
How to obtain and install R.ppt
rajalakshmi5921
 
Modeling in R Programming Language for Beginers.ppt
anshikagoel52
 
Lecture1_R.ppt
vikassingh569137
 
Lecture1_R.ppt
ArchishaKhandareSS20
 
Lecture1 r
Sandeep242951
 
Lecture1_R.pdf
BusyBird2
 
Lecture1_R Programming Introduction1.ppt
premak23
 
R-Language-Lab-Manual-lab-1.pdf
KabilaArun
 
R-Language-Lab-Manual-lab-1.pdf
attalurilalitha
 
R-Language-Lab-Manual-lab-1.pdf
DrGSakthiGovindaraju
 
Advanced Data Analytics with R Programming.ppt
Anshika865276
 
Brief introduction to R Lecturenotes1_R .ppt
geethar79
 
R_Language_study_forstudents_R_Material.ppt
Suresh Babu
 
Introduction+to+R.pdf
MudasserAziz2
 
Ad

More from Venkata Reddy Konasani (19)

PDF
Transformers 101
Venkata Reddy Konasani
 
PDF
Machine Learning Deep Learning AI and Data Science
Venkata Reddy Konasani
 
PDF
Model selection and cross validation techniques
Venkata Reddy Konasani
 
PDF
Neural Network Part-2
Venkata Reddy Konasani
 
PDF
GBM theory code and parameters
Venkata Reddy Konasani
 
PDF
Table of Contents - Practical Business Analytics using SAS
Venkata Reddy Konasani
 
PPTX
SAS basics Step by step learning
Venkata Reddy Konasani
 
DOCX
L101 predictive modeling case_study
Venkata Reddy Konasani
 
PDF
Online data sources for analaysis
Venkata Reddy Konasani
 
PDF
A data analyst view of Bigdata
Venkata Reddy Konasani
 
PDF
Big data Introduction by Mohan
Venkata Reddy Konasani
 
PDF
Data Analyst - Interview Guide
Venkata Reddy Konasani
 
PDF
Testing of hypothesis
Venkata Reddy Konasani
 
PDF
Multiple regression
Venkata Reddy Konasani
 
PDF
Logistic regression
Venkata Reddy Konasani
 
PDF
Statistical Distributions
Venkata Reddy Konasani
 
PDF
Descriptive statistics
Venkata Reddy Konasani
 
PDF
Data Exploration, Validation and Sanitization
Venkata Reddy Konasani
 
Transformers 101
Venkata Reddy Konasani
 
Machine Learning Deep Learning AI and Data Science
Venkata Reddy Konasani
 
Model selection and cross validation techniques
Venkata Reddy Konasani
 
Neural Network Part-2
Venkata Reddy Konasani
 
GBM theory code and parameters
Venkata Reddy Konasani
 
Table of Contents - Practical Business Analytics using SAS
Venkata Reddy Konasani
 
SAS basics Step by step learning
Venkata Reddy Konasani
 
L101 predictive modeling case_study
Venkata Reddy Konasani
 
Online data sources for analaysis
Venkata Reddy Konasani
 
A data analyst view of Bigdata
Venkata Reddy Konasani
 
Big data Introduction by Mohan
Venkata Reddy Konasani
 
Data Analyst - Interview Guide
Venkata Reddy Konasani
 
Testing of hypothesis
Venkata Reddy Konasani
 
Multiple regression
Venkata Reddy Konasani
 
Logistic regression
Venkata Reddy Konasani
 
Statistical Distributions
Venkata Reddy Konasani
 
Descriptive statistics
Venkata Reddy Konasani
 
Data Exploration, Validation and Sanitization
Venkata Reddy Konasani
 

Recently uploaded (20)

PPTX
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
PPTX
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
PDF
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PPTX
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
Horarios de distribución de agua en julio
pegazohn1978
 
PPTX
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Neurodivergent Friendly Schools - Slides from training session
Pooky Knightsmith
 
GRADE-3-PPT-EVE-2025-ENG-Q1-LESSON-1.pptx
EveOdrapngimapNarido
 
Exploring the Different Types of Experimental Research
Thelma Villaflores
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Aprendendo Arquitetura Framework Salesforce - Dia 03
Mauricio Alexandre Silva
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Universal immunization Programme (UIP).pptx
Vishal Chanalia
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Reconstruct, Restore, Reimagine: New Perspectives on Stoke Newington’s Histor...
History of Stoke Newington
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
Horarios de distribución de agua en julio
pegazohn1978
 
CATEGORIES OF NURSING PERSONNEL: HOSPITAL & COLLEGE
PRADEEP ABOTHU
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 

R- Introduction

  • 2. • • • • • • • • What is R R basics Working with R R packages R Functions Importing & Exporting data Creating calculated fields R Help & Tutorials Data Analysis Course Venkat Reddy Contents 2
  • 3. • Programming “environment” • Runs on a variety of platforms including Windows, Unix and MacOS. • Provides an unparalleled platform for programming new statistical methods in an easy and straightforward manner. • Object-oriented • Open source • Excellent graphics capabilities • Supported by a large user network Data Analysis Course Venkat Reddy R 3
  • 4. Downloading Data Analysis Course Venkat Reddy • Google it using R or CRAN (Comprehensive R Archive Network) • http://www.r-project.org 4
  • 6. Data Analysis Course Venkat Reddy R Studio 6
  • 7. • • • • • 2+2 log(10) help(log) summary(airquality) demo(graphics) # pretty pictures... Data Analysis Course Venkat Reddy R-Demo 7
  • 8. R-Basics :Naming convention • must start with a letter (A-Z or a-z) • can contain letters, digits (0-9), and/or periods “.” • mydata different from MyData Data Analysis Course Venkat Reddy • R is a case sensitive language. 8
  • 9. R-Basics :Assignment • “<-” used to indicate assignment • Assignment to an object is denoted by ”<-” or ”->” or ”=”. • If you see a notation ”= =”, you’ll looking at a comparison operator. – Many other notations can be found from the documentation for the Base package or R. Data Analysis Course Venkat Reddy • x<-c(1,2,3,4,5,6,7) • x<-c(1:7) • x<-1:4 9
  • 10. • during an R session, all objects are stored in a temporary, working memory • Commands are entered interactively at the R user prompt. Up and down arrow keys scroll through your command history. • list objects ls() • remove objects rm() • data() Data Analysis Course Venkat Reddy Workspace 10
  • 11. • • • • • • • • • • x <- round(rnorm(10,mean=20,sd=5)) # simulate data x mean(x) m <- mean(x) m x- m # notice recycling (x - m)^2 sum((x - m)^2) data() UKgas Data Analysis Course Venkat Reddy Demo: Working with R 11
  • 12. • R consists of a core and packages. Packages contain functions that are not available in the core. • Collections of R functions, data, and compiled code • Well-defined format that ensures easy installation, a basic standard of documentation, and enhances portability and reliability • When you download R, already a number (around 30) of packages are downloaded as well. • You can use the function search to see a list of packages that are currently attached to the system, this list is also called the search path. • search() Data Analysis Course Venkat Reddy R Packages 12
  • 13. • Select the `Packages' menu and select `Install package...', a list of available packages on your system will be displayed. • Select one and click `OK', the package is now attached to your current R session. Via the library function • The library can also be used to list all the available libraries on your system with a short description. Run the function without any arguments Data Analysis Course Venkat Reddy R packages 13
  • 14. Demo: R packages Data Analysis Course Venkat Reddy • Install cluster package • Install plyr package (for string operations) 14
  • 15. Importing Data • Reading CSV file • X <-read.csv(“file.csv") • reads in data from an external file • d <- read.table("myfile", header=TRUE) • R has ODBC for connecting to other programs • R gets confused if you use a path in your code like c:mydocumentsmyfile.txt • This is because R sees "" as an escape character. Instead, use c:my documentsmyfile.txt or c:/mydocuments/myfile.txt Data Analysis Course Venkat Reddy • read.table() 15
  • 16. Demo: Importing data • petrol<-read.csv("C:UsersVENKATGoogle DriveTrainingRDataPetrol_Consuption.csv") • sales_data<-read.table("C:UsersVENKATGoogle DriveTrainingRDatasales.txt") • sales_data<-read.table("C:UsersVENKATGoogle DriveTrainingRDatasales.txt",header=TRUE) Data Analysis Course Venkat Reddy • Reading CSV file 16
  • 17. Exporting data • To A Tab Delimited Text File • write.table(mydata, "c:/mydata.txt", sep="t") • library(xlsReadWrite) • write.xls(mydata, "c:/mydata.xls") • To SAS • library(foreign) • write.foreign(mydata, "c:/mydata.txt", "c:/mydata.sas", package="SAS") Data Analysis Course Venkat Reddy • To an Excel Spreadsheet 17
  • 18. Demo: Exporting data Data Analysis Course Venkat Reddy • write.table(sales_data, "C:UsersVENKATGoogle DriveTrainingRDatasales_export.txt", sep="t") • write.table(sales_data, "C:UsersVENKATGoogle DriveTrainingRDatasales_export.csv", sep=",") 18
  • 19. R- Functions Numeric Functions Description abs(x) absolute value sqrt(x) square root ceiling(x) ceiling(3.475) is 4 floor(x) floor(3.475) is 3 trunc(x) trunc(5.99) is 5 round(x, digits=n) round(3.475, digits=2) is 3.48 signif(x, digits=n) signif(3.475, digits=2) is 3.5 cos(x), sin(x), tan(x) also acos(x), cosh(x), acosh(x), etc. log(x) natural logarithm log10(x) common logarithm exp(x) e^x Data Analysis Course Venkat Reddy Function 19
  • 21. Character Functions Description substr(x, start=n1, stop=n2) Extract or replace substrings in a character vector. x <- "abcdef" substr(x, 2, 4) is "bcd" substr(x, 2, 4) <- "22222" is "a222ef" grep(pattern, x , ignore.case=FALSE, fixed=FALSE) Search for pattern in x. If fixed =FALSE then pattern is a regular expression. If fixed=TRUE then pattern is a text string. Returns matching indices. grep("A", c("b","A","c"), fixed=TRUE) returns 2 sub(pattern, replacement, x, ignore.case =FALSE, fixed=FALSE) Find pattern in x and replace with replacement text. If fixed=FALSE then pattern is a regular expression. If fixed = T then pattern is a text string. sub("s",".","Hello There") returns "Hello.There" strsplit(x, split) Split the elements of character vector x at split. strsplit("abc", "") returns 3 element vector "a","b","c" paste(..., sep="") Concatenate strings after using sep string to seperate them. paste("x",1:3,sep="") returns c("x1","x2" "x3") paste("x",1:3,sep="M") returns c("xM1","xM2" "xM3") paste("Today is", date()) toupper(x) Uppercase Data Analysis Course Venkat Reddy Function 21
  • 22. Demo :Character Functions Data Analysis Course Venkat Reddy • cust_id<-"Cust1233416" • id<-substr(cust_id, 5,10) • Up=toupper(cust_id) 22
  • 23. Calculated Fields in R • • • • • • mydata$sum <- mydata$x1 + mydata$x2 mydata$mean <- (mydata$x1 + mydata$x2)/2 attach(mydata) mydata$sum <- x1 + x2 mydata$mean <- (x1 + x2)/2 detach(mydata) Data Analysis Course Venkat Reddy • Use the assignment operator <- to create new variables. A wide array of operators and functions are available here. 23
  • 25. • If you encounter a new command during the exercises, and you’d like to know what it does, please consult the documentation. All R commands are listed nowhere, and the only way to get to know new commands is to read the documentation files, so we’d like you to practise this youself. • Tutorials Each of the following tutorials are in PDF format. • P. Kuhnert & B. Venables, An Introduction to R: Software for Statistical Modeling & Computing • J.H. Maindonald, Using R for Data Analysis and Graphics • B. Muenchen, R for SAS and SPSS Users • W.J. Owen, The R Guide • D. Rossiter, Introduction to the R Project for Statistical Computing for Use at the ITC • W.N. Venebles & D. M. Smith, An Introduction to R Data Analysis Course Venkat Reddy R-Help 25
  • 26. R-Tutorials Paul Geissler's excellent R tutorial Dave Robert's Excellent Labs on Ecological Analysis Excellent Tutorials by David Rossitier Excellent tutorial an nearly every aspect of R (c/o Rob Kabacoff) MOST of these notes follow this web page format • Introduction to R by Vincent Zoonekynd • R Cookbook • Data Manipulation Reference Data Analysis Course Venkat Reddy • • • • 26
  • 27. Data Analysis Course Venkat Reddy Thank you 27