SlideShare a Scribd company logo
R Language

dwivedishashwat@gmail.com
Background

• 1991: Created by Ross Ihaka and Robert Gentleman
• 2000: R version 1.0.0 is released
• Latest version is 2.15.2 released in Oct „12

• R version 2.15.3 is scheduled to release in Mar „12
and 3.0.0 is scheduled to be released in Apr ‟13
• http://www.r-project.org (basic information about R)
• http://www.cran.r-project.org (base system and
additional packages)
• help() or ?help, help.search() or ??help
Background

• R is a free software environment for
statistical computing and graphics
• Very active and vibrant user community
• Graphical capabilities
• Physical memory
• Base R and around 4000 packages

1/21/2014
Introduction
 memory.limit(): To find out maximum amount of available
physical memory
 memory.size(): To find out how much memory is in use
 getwd(): Shows the path of your current working directory
 setwd(path): Allows you to set a new path for your current
working directory

 dir(): List down all the files in your working directory
 Program Editor (open, load, run, save)
• ls(): List all objects in your workspace

• rm(): Removes object from your workspace
Introduction

 Commands to R are expressions (4/3) or assignments (x <- 4/3)
 R is case sensitive
 Everything in R is a object
 Normally R objects are accessed by their names which is made up from letters,
and digits (0 to 9) or a period (“.”) in non-initial positions.
 Every object has a class
 R has 5 basic classes of objects
 character
 numeric (real numbers)
 integers
 complex
 logical (True / False)

•

The most basic object is a vector

 A vector can only contains objects of the same class
Background
•

Ex.

•

 x <- 1 # assignment
 Print(x) # explicit printing
 X # auto printing
Ex.









•

Q.




•

x <- c(0.5, 0.6) # numeric
X <- c(TRUE, FALSE) # logical
X <- c(T, F) # logical
X <- c(“a”, “b”, “c”, “d”) # character
X <- 1:20 # integer
X <- c(1+0i, 2+4i) #complex
seq(from=1, to=10, by=1)
rep(c(1,2,3,4,5), times=2, each=2)

X <- c(1.7, “a”)
X <- c(TRUE, 2)
X <- c(“a”, TRUE)

When different objects are mixed in a vector, coercion occurs so that every element in the
vector is of same class
Session 1 Remaining

• rep(x, times, length.out, each)
• rm()
• rm(list=ls(pattern=“^test”))
• rm(list=ls(pattern=“test”))
• rm(list=setdiff(ls(), “test”))
• rm(list=ls())
Introduction

• Ex.
 X <- 0:6
 X <- c(“a”, “b”, “c”)
 X <- c(1, 2, 3)

 Numbers in R generally treated as numeric (i.e. double precision
real numbers)
 If you explicitly wants an integer then you need to specify L suffix
 Special number Inf (1/0), it actually a real number, 1/Inf will give
you 0
 Undefined value NaN (0/0) Not a Number, it can be though of as
missing value
• # indicates comments
Data Types

 R objects can have attributes (attributes())
 Class (class())
 Length (length())
 names (colnames for a matrix), dimnames (rownames, colnames for a matrix)

 dimensions (dim())
 other user defined attributes

 Various data types in R
 Vectors
 Vector(mode, length)

•

Lists: Special type of vectors which can contain objects of different
classes.

 x <- list(1,2,3,“a”,”b”,”c”)
 x <- list(a=c(1,2,3), b=1:4, c=c(“a”,”b”,”c”))
Data Types
 Matrix: vectors with dimension attribute. Dimension itself is an
integer vector of length 2 (nrow, ncol). Matrices are constructed
column wise.







m <- matrix(nrow=2, ncol=3)
m <- matrix(1:6, nrow=2, ncol=3)
x <- 1:3
y <- 10:12
cbind(x, y)
rbind(x,y)

 Data frames (data.frame())
 https://stat.ethz.ch/pipermail/rhelp/attachments/20101027/05a229bb/attachment.pl
 Factors: Used for categorical data i.e. Male & Female or analyst,
senior analyst, manager etc.






x <- factor(c(“a”, “b”, “b”, “c”, “c”, “c”, “d”))
levels()
unclass(x)
levels([4:6])
Levels([4:6, drop=TRUE])
Date & Time

 Converting a character variable to a date variable
 as.Date(variable_name, input_format)
 strptime(variable_name, input_format)
 Output will be %Y-%m-%d %H:%M:%S


%Y: Year with century



%m: Month as decimal number (01-12)



%d: Day of the month as decimal number(01-31)



%H: Hrs as decimal numbers (00-23)



%M: Minutes as decimal numbers (00-59)



%S: Seconda as decimal numbers (00-59)

 Converting a date variable to a character variable / formatting a date
variable
 strftime(date_variable_name, output_format)
 format(data_variable_name, output_format)
 as.character(date_variable_name, output_format)
Sub-setting

 [ always returns an object of the same class as the original; can be
used to select more than one element
 [[ is used to extract elements of list or data frames; it can only be
used to extract single element and the class of the returned object
will not necessarily be a list or data frame
 $ is used to extract elements of a list or data frames by names;
semantics are similar to [[
Operators

 <: Less than
 <=: Less than equals to
 >: Greater than
 >=: Greater than equals to
 ==: Exactly equals to
 !=: Not equal to

 | or II: OR
 & or &&: AND
 !: NOT
Some Examples

 x <- c(“a”, “b”, “c”, “c”, “d”, “a”)
 x[1], x[1:4], x[x > “a”], u <- x >”a”

 x <- matrix(1:6,2,3)
 x[1,2], x[1,], x[,1], x[1,2, drop=FALSE]

 x <- list(var_1=c(1:10), var_2=c(“a”, “b”, “c”), var_3=0.6)
 x[1], x[[1]], x$var_1
 name <- “var_1”, x[name], x[[name]], x$name
 x[c(1,3)], x[[c(1,3)]], x[[1]][[3]]

 Produce a character vector containing var_1, var_2, var_3… var_999
 Remove missing values from x <- c(1, 2, 3, NA, 4, 5, NA, 6)
 y <- c(“a”, “b”, NA, NA, “c”, “d”, “e”, “f”), prepare a matrix containing
two columns x & y and does not have any missing value
 What is the sum & mean of Wind for the observations which has
temperature greater then 60 & month equals to 5
 How to create a new directory with a given name
Reading / Writing Data Set
 Principle functions for reading data into R
 read.table(), read.csv(): Used for reading tabular data
 readLines(): For reading lines of a text file
 source(): For reading in R code file
 dget(): For reading in R code file
 load(): For reading in saved workspaces
 unserialize(): For reading single R objects in binary form

•

Principle functions for writing data to files

 write.table()
 writeLines()
 dump()
 dput()
 save()
 serialize()
Importing / Exporting Data

 Read.table() is one of the most commonly used function for reading data.
Few important arguments;
 file, name of the file to be read,
 header, logical indicating if the file has a header line
 sep, a string indicating how the columns are separated
 colClasses, a character vector indicating class of each column in the dataset
 nrows, the maximum number of rows to be read in the dataset
 na.strings, a character vector of strings which are to be interpreted as NA values
 comment.char, a character string indicating the comment character
 skip, number of lines to skip from beginning
 stringAsFactors, logical indicating should character variables be codes as factors

 Write.table()
 X, the object to be written, preferable a matrix or a data frame
 File, path and name of the file to be created
 Sep, a string indicating how the columns are separated
 Row.names, col.names, logical indicating whether the row names or col names to be
written along with x
Data Summary / Manipulation

 attach(x): For attaching a file
 detach(x): For detaching a file
•

summary(x): For displaying summary statistics of a data set

•

str(x): For displaying summary statistics of a data set in a different
manner then summary()

•

sort(): For sorting a vector or factor

•

order(): For ordering along more than one variable

•

merge(): Merge two data frames by common columns or row names, or
do other versions of database join operations

•

cut(x, breaks, labels): Divides the range of x into intervals and codes
the values in x according to which interval they fall. The leftmost
interval corresponds to level one, the next leftmost to level two and
so on.
 cut(x, 10, 1:10)
Data Summary / Manipulation

•

pretty(x, n): Compute a sequence of about n+1 equally spaced „round‟
values which cover the range of the values in x.
 pretty(x, 100)

•

substr(x, start, stop) <- value: Extract or replace substrings in a
character vector.

•

strsplit(): Split the elements of a character vector x into substrings
according to the matches to substring split within them.

•

rank(): Returns the sample ranks of the values in a vector. Ties (i.e.,
equal values) and missing values can be handled in several ways

•

aggregate(): Splits the data into subsets, computes summary statistics
for each, and returns the result in a convenient form.

 ddply(): For each subset of a data frame, apply function then combine
results into a data frame.
Control Structures

 Allows you to control the flow of execution of the program
 if, else (testing a condition)
 if (condition) {do something} else if {do something different} else {do something
different}

 for (executing a loop fixed number of times)
 for (i in 1:10) { do something}

 while (executing a loop while a condition is true)
 while (condition) { do something}

 repeat (execute a infinite loop)

 break (break the execution of a loop)
 next (skip a iteration of a loop)
 return (exit a function)

 Create a vector with all integers from 1 to 1000 and replace all even
number by their inverse
Loop Functions

 lapply: Returns a list of the same length as X, each element of which
is the result of applying FUN to the corresponding element of X
 lapply(airquality, mean)
 Calculate sum of all the variables of the airquality dataset excluding NAs

 sapply: Sapply is a user-friendly version of lapply by default returning
a vector or matrix if appropriate
 sapply(airquality, mean)
 Repeat the problem present in lapply using sapply and see the difference

 apply: Returns a vector or array or list of values obtained by applying
a function to margins of an array or matrix
 apply(airquality, 1, sum)
 Calculate deciles including min and max of all the variables of the dataset
airquality excluding NAs
 Calculate square of each element of a matrix with dimensions 10 & 2 and
entries 1 to 20
Loop Functions

 tapply: Apply a function to each cell of a ragged array, that is to
each (non-empty) group of values given by a unique combination of
the levels of certain factors
 tapply(airquality$Ozone, aiqruality$Month, sum)

 Calculate sum of Ozone variable for observations having month equals
to 5

 mapply: mapply is a multivariate version of sapply. mapply applies
FUN to the first elements of each argument, the second elements,
the third elements, and so on
 mapply(rep, 1:4, 4:1)
 Calculate sum of two lists with dimensions 10 & 2 and having entries 1
to 20, 101 to 120, 201 to 220 & 301 to 320
Plotting Functions
 plot(x,y)
 hist(x)
 par()
 pch: plotting symbol

 lty: line type
 lwd: line width
 col: plotting color
 las: axis label orientation
 bg: background color

 mar: margin size
 oma: outer margin size
 mfrow: number of plots per row, column (plots are filled row-wise)
 mfcol: number of plots per row, column (plots are filled column-wise)
Plotting Functions

 lines: add lines to the plot
 points: add points to the plot
 text: add text labels to the plot
 title: add annotations to x, y axis labels, title, subtitle, outer
margin

 mtext: add text to the margins of the plot
 axis: adding axis ticks/labels
Functions

 function ()
 Exact match –> Partial match –> Positional match
 Return value of a function is the last expression in the function body
to be evaluated
 Functions can be nested, so that a function can be defined inside
another function
 Functions can be passed as arguments to other functions
Debugging

• Primary tools for debugging functions in R
 traceback: prints out the function call stack after an error occurs; does
nothing if there is no error
 debug: flags a function for debug mode which allows you to step through
execution of a function one line at a time
 browser: suspends the execution of a function whenever it is called and
puts the function in debug mode
 trace: allows you to insert debugging code into a function at specific
places
 recover: allows you to modify the error behavior so that you can browse
the function call stack
Debugging

 Indications that something‟s is not right
 message: a generic notification/diagnostic message produced by the
message function; execution of the function continues

 warning: an indication that something is wrong but not necessarily
fatal produced by warning function‟ execution of the function
continues
 error: an indication that a fatal problem has occurred produced by
stop function; execution stops
 condition: a generic concept for indicating that something
unexpected can occur; programmers can create their own conditions
Thanks a lot
For Question Read more 

dwivedishashwat@gmail.com

More Related Content

What's hot

Introduction To R Language
Introduction To R LanguageIntroduction To R Language
Introduction To R Language
Gaurang Dobariya
 
Language R
Language RLanguage R
Language R
Girish Khanzode
 
Next Generation Programming in R
Next Generation Programming in RNext Generation Programming in R
Next Generation Programming in R
Florian Uhlitz
 
R programming intro with examples
R programming intro with examplesR programming intro with examples
R programming intro with examples
Dennis
 
R language
R languageR language
R language
LearningTech
 
R basics
R basicsR basics
R basics
FAO
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
Guy Lebanon
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
AmanBhalla14
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data Structure
Sakthi Dasans
 
R programming by ganesh kavhar
R programming by ganesh kavharR programming by ganesh kavhar
R programming by ganesh kavhar
Savitribai Phule Pune University
 
Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching module
Sander Timmer
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
Julian Hyde
 
Grouping & Summarizing Data in R
Grouping & Summarizing Data in RGrouping & Summarizing Data in R
Grouping & Summarizing Data in R
Jeffrey Breen
 
Data Management in Python
Data Management in PythonData Management in Python
Data Management in Python
Sankhya_Analytics
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
Alberto Labarga
 
2 R Tutorial Programming
2 R Tutorial Programming2 R Tutorial Programming
2 R Tutorial Programming
Sakthi Dasans
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
Unmesh Baile
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
Yogendra Chaubey
 
R factors
R   factorsR   factors
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
krishna singh
 

What's hot (20)

Introduction To R Language
Introduction To R LanguageIntroduction To R Language
Introduction To R Language
 
Language R
Language RLanguage R
Language R
 
Next Generation Programming in R
Next Generation Programming in RNext Generation Programming in R
Next Generation Programming in R
 
R programming intro with examples
R programming intro with examplesR programming intro with examples
R programming intro with examples
 
R language
R languageR language
R language
 
R basics
R basicsR basics
R basics
 
Data Analysis with R (combined slides)
Data Analysis with R (combined slides)Data Analysis with R (combined slides)
Data Analysis with R (combined slides)
 
R programming & Machine Learning
R programming & Machine LearningR programming & Machine Learning
R programming & Machine Learning
 
3 R Tutorial Data Structure
3 R Tutorial Data Structure3 R Tutorial Data Structure
3 R Tutorial Data Structure
 
R programming by ganesh kavhar
R programming by ganesh kavharR programming by ganesh kavhar
R programming by ganesh kavhar
 
Presentation R basic teaching module
Presentation R basic teaching modulePresentation R basic teaching module
Presentation R basic teaching module
 
Morel, a Functional Query Language
Morel, a Functional Query LanguageMorel, a Functional Query Language
Morel, a Functional Query Language
 
Grouping & Summarizing Data in R
Grouping & Summarizing Data in RGrouping & Summarizing Data in R
Grouping & Summarizing Data in R
 
Data Management in Python
Data Management in PythonData Management in Python
Data Management in Python
 
Introduction to R programming
Introduction to R programmingIntroduction to R programming
Introduction to R programming
 
2 R Tutorial Programming
2 R Tutorial Programming2 R Tutorial Programming
2 R Tutorial Programming
 
Best corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbaiBest corporate-r-programming-training-in-mumbai
Best corporate-r-programming-training-in-mumbai
 
R tutorial for a windows environment
R tutorial for a windows environmentR tutorial for a windows environment
R tutorial for a windows environment
 
R factors
R   factorsR   factors
R factors
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
 

Viewers also liked

An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)
Dataspora
 
Classification Model - Decision Tree
Classification Model -  Decision TreeClassification Model -  Decision Tree
Classification Model - Decision TreeVaibhav Jain
 
Classification model for predicting student's knowledge
Classification model for predicting student's knowledgeClassification model for predicting student's knowledge
Classification model for predicting student's knowledge
Ashish Ranjan
 
IDS alert classification model
IDS alert classification modelIDS alert classification model
IDS alert classification model
dilipjangam91
 
Simple Business Model Classification System: Business Model Pipes, Valleys, a...
Simple Business Model Classification System: Business Model Pipes, Valleys, a...Simple Business Model Classification System: Business Model Pipes, Valleys, a...
Simple Business Model Classification System: Business Model Pipes, Valleys, a...
Rod King, Ph.D.
 
Introduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing EnvironmentIntroduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing Environment
izahn
 
LSESU a Taste of R Language Workshop
LSESU a Taste of R Language WorkshopLSESU a Taste of R Language Workshop
LSESU a Taste of R Language Workshop
Korkrid Akepanidtaworn
 
Data Analytics with Pandas and Numpy - Python
Data Analytics with Pandas and Numpy - PythonData Analytics with Pandas and Numpy - Python
Data Analytics with Pandas and Numpy - Python
Chetan Khatri
 
R programming Basic & Advanced
R programming Basic & AdvancedR programming Basic & Advanced
R programming Basic & Advanced
Sohom Ghosh
 
Major issues in data mining
Major issues in data miningMajor issues in data mining
Major issues in data miningSlideshare
 
Chapter 4 Classification
Chapter 4 ClassificationChapter 4 Classification
Chapter 4 Classification
Khalid Elshafie
 
R language tutorial
R language tutorialR language tutorial
R language tutorial
David Chiu
 
Data Mining: Classification and analysis
Data Mining: Classification and analysisData Mining: Classification and analysis
Data Mining: Classification and analysis
DataminingTools Inc
 
Data mining: Classification and prediction
Data mining: Classification and predictionData mining: Classification and prediction
Data mining: Classification and prediction
DataminingTools Inc
 
R Language definition
R Language definitionR Language definition
R Language definition
湘云 黄
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
SlideShare
 

Viewers also liked (17)

An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)An Interactive Introduction To R (Programming Language For Statistics)
An Interactive Introduction To R (Programming Language For Statistics)
 
Classification Model - Decision Tree
Classification Model -  Decision TreeClassification Model -  Decision Tree
Classification Model - Decision Tree
 
Classification model for predicting student's knowledge
Classification model for predicting student's knowledgeClassification model for predicting student's knowledge
Classification model for predicting student's knowledge
 
IDS alert classification model
IDS alert classification modelIDS alert classification model
IDS alert classification model
 
Simple Business Model Classification System: Business Model Pipes, Valleys, a...
Simple Business Model Classification System: Business Model Pipes, Valleys, a...Simple Business Model Classification System: Business Model Pipes, Valleys, a...
Simple Business Model Classification System: Business Model Pipes, Valleys, a...
 
Introduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing EnvironmentIntroduction to the R Statistical Computing Environment
Introduction to the R Statistical Computing Environment
 
LSESU a Taste of R Language Workshop
LSESU a Taste of R Language WorkshopLSESU a Taste of R Language Workshop
LSESU a Taste of R Language Workshop
 
Data Analytics with Pandas and Numpy - Python
Data Analytics with Pandas and Numpy - PythonData Analytics with Pandas and Numpy - Python
Data Analytics with Pandas and Numpy - Python
 
R programming Basic & Advanced
R programming Basic & AdvancedR programming Basic & Advanced
R programming Basic & Advanced
 
Major issues in data mining
Major issues in data miningMajor issues in data mining
Major issues in data mining
 
Chapter 4 Classification
Chapter 4 ClassificationChapter 4 Classification
Chapter 4 Classification
 
R language tutorial
R language tutorialR language tutorial
R language tutorial
 
Data Mining: Classification and analysis
Data Mining: Classification and analysisData Mining: Classification and analysis
Data Mining: Classification and analysis
 
Data mining: Classification and prediction
Data mining: Classification and predictionData mining: Classification and prediction
Data mining: Classification and prediction
 
R Language definition
R Language definitionR Language definition
R Language definition
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
 
Slideshare ppt
Slideshare pptSlideshare ppt
Slideshare ppt
 

Similar to R language introduction

R Programming Reference Card
R Programming Reference CardR Programming Reference Card
R Programming Reference Card
Maurice Dawson
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
R Introduction
R IntroductionR Introduction
R Introduction
Sangeetha S
 
R workshop
R workshopR workshop
R workshop
Revanth19921
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
Kamarudheen KV
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
Dr Nisha Arora
 
20170509 rand db_lesugent
20170509 rand db_lesugent20170509 rand db_lesugent
20170509 rand db_lesugent
Prof. Wim Van Criekinge
 
Practical data science_public
Practical data science_publicPractical data science_public
Practical data science_public
Long Nguyen
 
Short Reference Card for R users.
Short Reference Card for R users.Short Reference Card for R users.
Short Reference Card for R users.
Dr. Volkan OBAN
 
Reference card for R
Reference card for RReference card for R
Reference card for R
Dr. Volkan OBAN
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
Mahmoud Shiri Varamini
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
University of Salerno
 
R Basics
R BasicsR Basics
@ R reference
@ R reference@ R reference
@ R reference
vickyrolando
 
R command cheatsheet.pdf
R command cheatsheet.pdfR command cheatsheet.pdf
R command cheatsheet.pdf
Ngcnh947953
 
Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017
Parth Khare
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
Baishampayan Ghose
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
Josh Doyle
 

Similar to R language introduction (20)

R Programming Reference Card
R Programming Reference CardR Programming Reference Card
R Programming Reference Card
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
R Introduction
R IntroductionR Introduction
R Introduction
 
R교육1
R교육1R교육1
R교육1
 
R workshop
R workshopR workshop
R workshop
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
 
20170509 rand db_lesugent
20170509 rand db_lesugent20170509 rand db_lesugent
20170509 rand db_lesugent
 
Practical data science_public
Practical data science_publicPractical data science_public
Practical data science_public
 
Short Reference Card for R users.
Short Reference Card for R users.Short Reference Card for R users.
Short Reference Card for R users.
 
Reference card for R
Reference card for RReference card for R
Reference card for R
 
An Intoduction to R
An Intoduction to RAn Intoduction to R
An Intoduction to R
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
R Basics
R BasicsR Basics
R Basics
 
@ R reference
@ R reference@ R reference
@ R reference
 
R command cheatsheet.pdf
R command cheatsheet.pdfR command cheatsheet.pdf
R command cheatsheet.pdf
 
Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017Big Data Mining in Indian Economic Survey 2017
Big Data Mining in Indian Economic Survey 2017
 
Pune Clojure Course Outline
Pune Clojure Course OutlinePune Clojure Course Outline
Pune Clojure Course Outline
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Ggplot2 v3
Ggplot2 v3Ggplot2 v3
Ggplot2 v3
 

More from Shashwat Shriparv

Learning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptxLearning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptx
Shashwat Shriparv
 
LibreOffice 7.3.pptx
LibreOffice 7.3.pptxLibreOffice 7.3.pptx
LibreOffice 7.3.pptx
Shashwat Shriparv
 
Kerberos Architecture.pptx
Kerberos Architecture.pptxKerberos Architecture.pptx
Kerberos Architecture.pptx
Shashwat Shriparv
 
Suspending a Process in Linux.pptx
Suspending a Process in Linux.pptxSuspending a Process in Linux.pptx
Suspending a Process in Linux.pptx
Shashwat Shriparv
 
Kerberos Architecture.pptx
Kerberos Architecture.pptxKerberos Architecture.pptx
Kerberos Architecture.pptx
Shashwat Shriparv
 
Command Seperators.pptx
Command Seperators.pptxCommand Seperators.pptx
Command Seperators.pptx
Shashwat Shriparv
 
Upgrading hadoop
Upgrading hadoopUpgrading hadoop
Upgrading hadoop
Shashwat Shriparv
 
Hadoop migration and upgradation
Hadoop migration and upgradationHadoop migration and upgradation
Hadoop migration and upgradation
Shashwat Shriparv
 
Hive query optimization infinity
Hive query optimization infinityHive query optimization infinity
Hive query optimization infinity
Shashwat Shriparv
 
H base introduction & development
H base introduction & developmentH base introduction & development
H base introduction & development
Shashwat Shriparv
 
My sql
My sqlMy sql
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
Shashwat Shriparv
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
Shashwat Shriparv
 
Introduction to apache hadoop
Introduction to apache hadoopIntroduction to apache hadoop
Introduction to apache hadoop
Shashwat Shriparv
 
Next generation technology
Next generation technologyNext generation technology
Next generation technology
Shashwat Shriparv
 
Configure h base hadoop and hbase client
Configure h base hadoop and hbase clientConfigure h base hadoop and hbase client
Configure h base hadoop and hbase client
Shashwat Shriparv
 

More from Shashwat Shriparv (20)

Learning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptxLearning Linux Series Administrator Commands.pptx
Learning Linux Series Administrator Commands.pptx
 
LibreOffice 7.3.pptx
LibreOffice 7.3.pptxLibreOffice 7.3.pptx
LibreOffice 7.3.pptx
 
Kerberos Architecture.pptx
Kerberos Architecture.pptxKerberos Architecture.pptx
Kerberos Architecture.pptx
 
Suspending a Process in Linux.pptx
Suspending a Process in Linux.pptxSuspending a Process in Linux.pptx
Suspending a Process in Linux.pptx
 
Kerberos Architecture.pptx
Kerberos Architecture.pptxKerberos Architecture.pptx
Kerberos Architecture.pptx
 
Command Seperators.pptx
Command Seperators.pptxCommand Seperators.pptx
Command Seperators.pptx
 
Upgrading hadoop
Upgrading hadoopUpgrading hadoop
Upgrading hadoop
 
Hadoop migration and upgradation
Hadoop migration and upgradationHadoop migration and upgradation
Hadoop migration and upgradation
 
Hive query optimization infinity
Hive query optimization infinityHive query optimization infinity
Hive query optimization infinity
 
H base introduction & development
H base introduction & developmentH base introduction & development
H base introduction & development
 
Hbase interact with shell
Hbase interact with shellHbase interact with shell
Hbase interact with shell
 
H base development
H base developmentH base development
H base development
 
Hbase
HbaseHbase
Hbase
 
H base
H baseH base
H base
 
My sql
My sqlMy sql
My sql
 
Apache tomcat
Apache tomcatApache tomcat
Apache tomcat
 
Linux 4 you
Linux 4 youLinux 4 you
Linux 4 you
 
Introduction to apache hadoop
Introduction to apache hadoopIntroduction to apache hadoop
Introduction to apache hadoop
 
Next generation technology
Next generation technologyNext generation technology
Next generation technology
 
Configure h base hadoop and hbase client
Configure h base hadoop and hbase clientConfigure h base hadoop and hbase client
Configure h base hadoop and hbase client
 

Recently uploaded

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
CarlosHernanMontoyab2
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 

Recently uploaded (20)

Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf678020731-Sumas-y-Restas-Para-Colorear.pdf
678020731-Sumas-y-Restas-Para-Colorear.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 

R language introduction

  • 2. Background • 1991: Created by Ross Ihaka and Robert Gentleman • 2000: R version 1.0.0 is released • Latest version is 2.15.2 released in Oct „12 • R version 2.15.3 is scheduled to release in Mar „12 and 3.0.0 is scheduled to be released in Apr ‟13 • http://www.r-project.org (basic information about R) • http://www.cran.r-project.org (base system and additional packages) • help() or ?help, help.search() or ??help
  • 3. Background • R is a free software environment for statistical computing and graphics • Very active and vibrant user community • Graphical capabilities • Physical memory • Base R and around 4000 packages 1/21/2014
  • 4. Introduction  memory.limit(): To find out maximum amount of available physical memory  memory.size(): To find out how much memory is in use  getwd(): Shows the path of your current working directory  setwd(path): Allows you to set a new path for your current working directory  dir(): List down all the files in your working directory  Program Editor (open, load, run, save) • ls(): List all objects in your workspace • rm(): Removes object from your workspace
  • 5. Introduction  Commands to R are expressions (4/3) or assignments (x <- 4/3)  R is case sensitive  Everything in R is a object  Normally R objects are accessed by their names which is made up from letters, and digits (0 to 9) or a period (“.”) in non-initial positions.  Every object has a class  R has 5 basic classes of objects  character  numeric (real numbers)  integers  complex  logical (True / False) • The most basic object is a vector  A vector can only contains objects of the same class
  • 6. Background • Ex. •  x <- 1 # assignment  Print(x) # explicit printing  X # auto printing Ex.         • Q.    • x <- c(0.5, 0.6) # numeric X <- c(TRUE, FALSE) # logical X <- c(T, F) # logical X <- c(“a”, “b”, “c”, “d”) # character X <- 1:20 # integer X <- c(1+0i, 2+4i) #complex seq(from=1, to=10, by=1) rep(c(1,2,3,4,5), times=2, each=2) X <- c(1.7, “a”) X <- c(TRUE, 2) X <- c(“a”, TRUE) When different objects are mixed in a vector, coercion occurs so that every element in the vector is of same class
  • 7. Session 1 Remaining • rep(x, times, length.out, each) • rm() • rm(list=ls(pattern=“^test”)) • rm(list=ls(pattern=“test”)) • rm(list=setdiff(ls(), “test”)) • rm(list=ls())
  • 8. Introduction • Ex.  X <- 0:6  X <- c(“a”, “b”, “c”)  X <- c(1, 2, 3)  Numbers in R generally treated as numeric (i.e. double precision real numbers)  If you explicitly wants an integer then you need to specify L suffix  Special number Inf (1/0), it actually a real number, 1/Inf will give you 0  Undefined value NaN (0/0) Not a Number, it can be though of as missing value • # indicates comments
  • 9. Data Types  R objects can have attributes (attributes())  Class (class())  Length (length())  names (colnames for a matrix), dimnames (rownames, colnames for a matrix)  dimensions (dim())  other user defined attributes  Various data types in R  Vectors  Vector(mode, length) • Lists: Special type of vectors which can contain objects of different classes.  x <- list(1,2,3,“a”,”b”,”c”)  x <- list(a=c(1,2,3), b=1:4, c=c(“a”,”b”,”c”))
  • 10. Data Types  Matrix: vectors with dimension attribute. Dimension itself is an integer vector of length 2 (nrow, ncol). Matrices are constructed column wise.       m <- matrix(nrow=2, ncol=3) m <- matrix(1:6, nrow=2, ncol=3) x <- 1:3 y <- 10:12 cbind(x, y) rbind(x,y)  Data frames (data.frame())  https://stat.ethz.ch/pipermail/rhelp/attachments/20101027/05a229bb/attachment.pl  Factors: Used for categorical data i.e. Male & Female or analyst, senior analyst, manager etc.      x <- factor(c(“a”, “b”, “b”, “c”, “c”, “c”, “d”)) levels() unclass(x) levels([4:6]) Levels([4:6, drop=TRUE])
  • 11. Date & Time  Converting a character variable to a date variable  as.Date(variable_name, input_format)  strptime(variable_name, input_format)  Output will be %Y-%m-%d %H:%M:%S  %Y: Year with century  %m: Month as decimal number (01-12)  %d: Day of the month as decimal number(01-31)  %H: Hrs as decimal numbers (00-23)  %M: Minutes as decimal numbers (00-59)  %S: Seconda as decimal numbers (00-59)  Converting a date variable to a character variable / formatting a date variable  strftime(date_variable_name, output_format)  format(data_variable_name, output_format)  as.character(date_variable_name, output_format)
  • 12. Sub-setting  [ always returns an object of the same class as the original; can be used to select more than one element  [[ is used to extract elements of list or data frames; it can only be used to extract single element and the class of the returned object will not necessarily be a list or data frame  $ is used to extract elements of a list or data frames by names; semantics are similar to [[
  • 13. Operators  <: Less than  <=: Less than equals to  >: Greater than  >=: Greater than equals to  ==: Exactly equals to  !=: Not equal to  | or II: OR  & or &&: AND  !: NOT
  • 14. Some Examples  x <- c(“a”, “b”, “c”, “c”, “d”, “a”)  x[1], x[1:4], x[x > “a”], u <- x >”a”  x <- matrix(1:6,2,3)  x[1,2], x[1,], x[,1], x[1,2, drop=FALSE]  x <- list(var_1=c(1:10), var_2=c(“a”, “b”, “c”), var_3=0.6)  x[1], x[[1]], x$var_1  name <- “var_1”, x[name], x[[name]], x$name  x[c(1,3)], x[[c(1,3)]], x[[1]][[3]]  Produce a character vector containing var_1, var_2, var_3… var_999  Remove missing values from x <- c(1, 2, 3, NA, 4, 5, NA, 6)  y <- c(“a”, “b”, NA, NA, “c”, “d”, “e”, “f”), prepare a matrix containing two columns x & y and does not have any missing value  What is the sum & mean of Wind for the observations which has temperature greater then 60 & month equals to 5  How to create a new directory with a given name
  • 15. Reading / Writing Data Set  Principle functions for reading data into R  read.table(), read.csv(): Used for reading tabular data  readLines(): For reading lines of a text file  source(): For reading in R code file  dget(): For reading in R code file  load(): For reading in saved workspaces  unserialize(): For reading single R objects in binary form • Principle functions for writing data to files  write.table()  writeLines()  dump()  dput()  save()  serialize()
  • 16. Importing / Exporting Data  Read.table() is one of the most commonly used function for reading data. Few important arguments;  file, name of the file to be read,  header, logical indicating if the file has a header line  sep, a string indicating how the columns are separated  colClasses, a character vector indicating class of each column in the dataset  nrows, the maximum number of rows to be read in the dataset  na.strings, a character vector of strings which are to be interpreted as NA values  comment.char, a character string indicating the comment character  skip, number of lines to skip from beginning  stringAsFactors, logical indicating should character variables be codes as factors  Write.table()  X, the object to be written, preferable a matrix or a data frame  File, path and name of the file to be created  Sep, a string indicating how the columns are separated  Row.names, col.names, logical indicating whether the row names or col names to be written along with x
  • 17. Data Summary / Manipulation  attach(x): For attaching a file  detach(x): For detaching a file • summary(x): For displaying summary statistics of a data set • str(x): For displaying summary statistics of a data set in a different manner then summary() • sort(): For sorting a vector or factor • order(): For ordering along more than one variable • merge(): Merge two data frames by common columns or row names, or do other versions of database join operations • cut(x, breaks, labels): Divides the range of x into intervals and codes the values in x according to which interval they fall. The leftmost interval corresponds to level one, the next leftmost to level two and so on.  cut(x, 10, 1:10)
  • 18. Data Summary / Manipulation • pretty(x, n): Compute a sequence of about n+1 equally spaced „round‟ values which cover the range of the values in x.  pretty(x, 100) • substr(x, start, stop) <- value: Extract or replace substrings in a character vector. • strsplit(): Split the elements of a character vector x into substrings according to the matches to substring split within them. • rank(): Returns the sample ranks of the values in a vector. Ties (i.e., equal values) and missing values can be handled in several ways • aggregate(): Splits the data into subsets, computes summary statistics for each, and returns the result in a convenient form.  ddply(): For each subset of a data frame, apply function then combine results into a data frame.
  • 19. Control Structures  Allows you to control the flow of execution of the program  if, else (testing a condition)  if (condition) {do something} else if {do something different} else {do something different}  for (executing a loop fixed number of times)  for (i in 1:10) { do something}  while (executing a loop while a condition is true)  while (condition) { do something}  repeat (execute a infinite loop)  break (break the execution of a loop)  next (skip a iteration of a loop)  return (exit a function)  Create a vector with all integers from 1 to 1000 and replace all even number by their inverse
  • 20. Loop Functions  lapply: Returns a list of the same length as X, each element of which is the result of applying FUN to the corresponding element of X  lapply(airquality, mean)  Calculate sum of all the variables of the airquality dataset excluding NAs  sapply: Sapply is a user-friendly version of lapply by default returning a vector or matrix if appropriate  sapply(airquality, mean)  Repeat the problem present in lapply using sapply and see the difference  apply: Returns a vector or array or list of values obtained by applying a function to margins of an array or matrix  apply(airquality, 1, sum)  Calculate deciles including min and max of all the variables of the dataset airquality excluding NAs  Calculate square of each element of a matrix with dimensions 10 & 2 and entries 1 to 20
  • 21. Loop Functions  tapply: Apply a function to each cell of a ragged array, that is to each (non-empty) group of values given by a unique combination of the levels of certain factors  tapply(airquality$Ozone, aiqruality$Month, sum)  Calculate sum of Ozone variable for observations having month equals to 5  mapply: mapply is a multivariate version of sapply. mapply applies FUN to the first elements of each argument, the second elements, the third elements, and so on  mapply(rep, 1:4, 4:1)  Calculate sum of two lists with dimensions 10 & 2 and having entries 1 to 20, 101 to 120, 201 to 220 & 301 to 320
  • 22. Plotting Functions  plot(x,y)  hist(x)  par()  pch: plotting symbol  lty: line type  lwd: line width  col: plotting color  las: axis label orientation  bg: background color  mar: margin size  oma: outer margin size  mfrow: number of plots per row, column (plots are filled row-wise)  mfcol: number of plots per row, column (plots are filled column-wise)
  • 23. Plotting Functions  lines: add lines to the plot  points: add points to the plot  text: add text labels to the plot  title: add annotations to x, y axis labels, title, subtitle, outer margin  mtext: add text to the margins of the plot  axis: adding axis ticks/labels
  • 24. Functions  function ()  Exact match –> Partial match –> Positional match  Return value of a function is the last expression in the function body to be evaluated  Functions can be nested, so that a function can be defined inside another function  Functions can be passed as arguments to other functions
  • 25. Debugging • Primary tools for debugging functions in R  traceback: prints out the function call stack after an error occurs; does nothing if there is no error  debug: flags a function for debug mode which allows you to step through execution of a function one line at a time  browser: suspends the execution of a function whenever it is called and puts the function in debug mode  trace: allows you to insert debugging code into a function at specific places  recover: allows you to modify the error behavior so that you can browse the function call stack
  • 26. Debugging  Indications that something‟s is not right  message: a generic notification/diagnostic message produced by the message function; execution of the function continues  warning: an indication that something is wrong but not necessarily fatal produced by warning function‟ execution of the function continues  error: an indication that a fatal problem has occurred produced by stop function; execution stops  condition: a generic concept for indicating that something unexpected can occur; programmers can create their own conditions
  • 27. Thanks a lot For Question Read more  dwivedishashwat@gmail.com