SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Downloaden Sie, um offline zu lesen
Dr Nisha Arora
Data Types & Operators in R
Contents
2
Variable assignment in R
Numerical Operators in R
In built functions in R
Infinity, NA and NAN values in R
Atomic data types in R
Coercion
Variable Assignment in R
3
Variables:
Variables are used to store data, which can vary
Unique name given to variable (function and objects as well) is
known as identifier.
To assign value to a variable named ‘x’
x <- value or x = value
x <<- value or value -> x or value ->> x
Variable Names
4
Some Rules:
✓ An identifier can contain letters, numbers, dots(.) and underscores ( _ )
✓ It should not have other special characters or blank space in the name
✓ It should not start with a dot followed by a number (eg:- .2iota)
✓ It should not start with an underscore or a number (eg:- _iota or 1more)
✓ It should not be a reserved keyword like for, if, else, in, next, etc.
Note: R is case-sensitive
Variable Names
5
Not Allowed Allowed
monthly salary monthly_salary or
monthly.salary or
MonthlySalary
%growth perc_growth
This&that This.that
2ndhighest Second.highest
Some Examples:
Numerical Operators in R
6
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
%/% Integer division
%% Modulo (estimates remainder in a division)
^ or ** Exponentiation
Relational Operators in R
7
Operator Description
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
== Exactly equal to
!= Not equal to
Logical Operators in R
8
Operator Description
x |y Element-wise OR operator
x & y Element-wise AND operator
! x Not Operator
X || y Takes only first element of iterables
X && y Takes only first element of iterables
Inbuilt Mathematical Functions
9
pi; exp(1)
log(x) # log to base e of x
log10(x) # log to base 10 of x
log(x,n) # log to base n of x
floor(x) # greatest integer <x
ceiling(x) # smallest integer >x
lgamma(x) # natural log of gamma (x)
choose(n,x) # Binomial coefficient nCx
sqrt(x); factorial(x); gamma(x)
Inbuilt Mathematical Functions
10
trunc(x) # closest integer to x between x and 0
E.g., trunc(1.5) =1, trunc(-1.5) = -1
NOTE: trunc is like floor for positive values and like ceiling for
negative values
round(x, digits=0) # round the value of x to an integer
signif(x, digits=6) # give x to 6 digits in scientific notation
runif(n) # generates n random numbers
between 0 and 1 from a uniform distribution
Inbuilt Trigonometrically Functions
11
cos(x) # cosine of x in radians
sin(x) # sine of x in radians
tan(x) # tangent of x in radians
acos(x), asin(x), atan(x) # inverse trigonometric
transformations of real or complex numbers
acosh(x), asinh(x), atanh(x) # inverse hyperbolic
trigonometric transformations of real or complex numbers
abs(x) # the absolute value of x,
ignoring the minus sign if there is one
12
Data types in R
✓ Logical, for example, TRUE, FALSE
✓ Numeric (sometimes called double, usually treated as floating
point number/real number), for example, 11.7, -3, 99.0, 1000
✓ Integer, for example, 25L, 0L, -33L
Specify L suffix to get integer (i.e. 1L gives integer 1)
✓ Complex, for example, 3 – 4i, 4+5i
✓ Character, for example, “abc”, “34”, “TRUE”, “3-4i”, ‘3L’
13
Data types in R
✓ To check the class of variables, class() command can be
used
For example:
class(7); class(7L); class(T); class(‘T’); class(3+0i)
✓ Special numbers such as Inf and NAN are of numeric
class
For example: class(8/0); class(0/0)
14
Coercion
All elements of a vector must be the same type, so when we
attempt to combine different types they will be coerced to the
most flexible type.
Types from least to most flexible are:
.
Logical
Integer
Double/ Numeric
Complex
Character
15
Coercion
When a logical vector is coerced to an integer or double, TRUE
becomes 1 and FALSE becomes 0
x <- c(FALSE, FALSE, TRUE); as.numeric(x)
Total number of TRUEs
sum(x)
Proportion that are TRUE
mean(x)
16
Coercion in R
✓ To forcefully coerce a variable class into other, following
functions are used
as.numeric(), as.logical(), etc.
In Python, we call it ‘typecasting’
https://youtu.be/FJ6IkFycCdA
17
NA’s and NAN’s in R
Inf
Infinity
NA
Not available, generally interpreted as a missing value
The default type of NA is logical, unless coerced to some other type,
so the appearance of a missing value may trigger logical rather than
numeric indexing.
Numeric and logical calculations with NA generally return NA.
NAN
Not a number, e.g., 0/0
18
NA’s and NAN’s in R
✓ is.nan() is used to test for NaN's
✓ is.na() is used to test, if objects are NA's
✓ A NAN value can also be NA but not conversely.
✓ It means is.na also returns TRUE for NaN’s
✓ Functions like mean() and sum() on vector
containing NA or NaN, they will return NA and NaN.
✓ This behavior alerts you to the presence of the bad value.
19
NULL in R
✓ NULL is different from the NA and NAN
✓ NULL means that there is no value, while NA and NaN
mean that there is some value, although one that is
perhaps not usable.
✓ is.null() is used to test for NULL
✓ Functions like mean() and sum() on vector
containing NULL doesn’t pose any issue as NULL value
simply doesn’t exists
20
Data Type Conversions
Use is.foo to test for data type foo.
Returns TRUE or FALSE
Use as.foo to explicitly convert it.
Examples:
is.numeric(), is.character(), is.vector(), is.matrix(), is.data.frame()
as.numeric(), as.character(), as.vector(), as.matrix(), as.data.frame)
21
Handling of missing values
X <- c(1:8,NA)
✓ Removing missing vlaues
mean(X, na.rm = T) or mean(X ,na.rm=TRUE)
✓ To check for the location of missing values within a vector
which(is.na(X))
✓ To assign this a large number, say, 999
X[which(is.na(X))] = 999
22
Handling of missing values
x <- c(1, 2, NA, 4, NA, 5)
✓ Identify missing values
bad <- is.na(x)
✓ To remove missing values
x[!bad]
23
Handling of missing values
x <- c(1, 2, NA, 4, NA, 5); y <- c("a", "b", NA, "d", "e", NA)
df = data.frame(x,y)
✓ To take the subset of data frame with no missing value
good = complete.cases(x,y); good
✓ To take the subset of vector x with no missing value
x[good]
✓ To take the subset of vector y with no missing value
y[good]
Function Composition Pipe Operator
https://www.linkedin.com/posts/drnishaarora_programming-r-rstats-activity-6783610405076914176-23p-
https://github.com/arora123/R-for-Data-Science/blob/master/pipe%20operator%20in%20R.R
Books
25
✓ Crowley, M. J. (2007). The R Book. Chichester, New
England: John Wiley & Sons, Ltd.
✓ An Introduction to R by W. N. Venables, D. M. Smith and
the R Core Team
✓ R in a Nutshell by Joseph Adler: O’Reilly
✓ Teetor, P. (2011). R cookbook. Sebastopol, CA: O’Reilly
Media Inc.
Books
26
✓ Bio Statistics - https://www.middleprofessor.com/files/applied-
biostatistics_bookdown/_book/
✓ Advanced R - https://adv-r.hadley.nz/
✓ Data Visualization - https://rkabacoff.github.io/datavis/
✓ R for Data Science - https://r4ds.had.co.nz/index.html
✓ Data Exploration & Analysis -
https://bookdown.org/mikemahoney218/IDEAR/
✓ https://bookdown.org/mikemahoney218/LectureBook/
Blogs & Communities
27
http://www.r-bloggers.com/
http://www.inside-r.org/blogs
https://blog.rstudio.org/
http://www.statmethods.net/
http://stats.stackexchange.com
https://www.researchgate.net
https://www.quora.com
https://github.com
Learn To Code
28
https://www.datacamp.com/
https://www.dataquest.io/
https://www.codeschool.com/
https://guide.freecodecamp.org/r/
https://www.hackerrank.com/contests/co/
https://www.hackerearth.com/practice/
https://hackernoon.com/tagged/r
https://rpubs.com/
29
Reach Out to Me
http://stats.stackexchange.com/users/79100/learner
https://www.researchgate.net/profile/Nisha_Arora2/contributions
https://www.quora.com/profile/Nisha-Arora-9
https://github.com/arora123/
https://www.youtube.com/channel/UCniyhvrD_8AM2jXki3eEErw
https://www.linkedin.com/in/drnishaarora/
Dr.aroranisha@gmail.com
Thank You

Weitere ähnliche Inhalte

Was ist angesagt?

Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
Aakash deep Singhal
 

Was ist angesagt? (20)

Data Structures Chapter-2
Data Structures Chapter-2Data Structures Chapter-2
Data Structures Chapter-2
 
Chart and graphs in R programming language
Chart and graphs in R programming language Chart and graphs in R programming language
Chart and graphs in R programming language
 
Data structures chapter 1
Data structures chapter  1Data structures chapter  1
Data structures chapter 1
 
R Datatypes
R DatatypesR Datatypes
R Datatypes
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
 
R Programming: Introduction To R Packages
R Programming: Introduction To R PackagesR Programming: Introduction To R Packages
R Programming: Introduction To R Packages
 
Vector in R
Vector in RVector in R
Vector in R
 
Import Data using R
Import Data using R Import Data using R
Import Data using R
 
Evaluation metrics: Precision, Recall, F-Measure, ROC
Evaluation metrics: Precision, Recall, F-Measure, ROCEvaluation metrics: Precision, Recall, F-Measure, ROC
Evaluation metrics: Precision, Recall, F-Measure, ROC
 
Data Types and Structures in R
Data Types and Structures in RData Types and Structures in R
Data Types and Structures in R
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
 
Lecture 1 data structures and algorithms
Lecture 1 data structures and algorithmsLecture 1 data structures and algorithms
Lecture 1 data structures and algorithms
 
Character Array and String
Character Array and StringCharacter Array and String
Character Array and String
 
Data preprocessing
Data preprocessingData preprocessing
Data preprocessing
 
Exploratory data analysis data visualization
Exploratory data analysis data visualizationExploratory data analysis data visualization
Exploratory data analysis data visualization
 
Regular expressions in Python
Regular expressions in PythonRegular expressions in Python
Regular expressions in Python
 
UNIT I LINEAR DATA STRUCTURES – LIST
UNIT I 	LINEAR DATA STRUCTURES – LIST 	UNIT I 	LINEAR DATA STRUCTURES – LIST
UNIT I LINEAR DATA STRUCTURES – LIST
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Python set
Python setPython set
Python set
 
Attribute oriented analysis
Attribute oriented analysisAttribute oriented analysis
Attribute oriented analysis
 

Ähnlich wie 2 data types and operators in r

Mathematics power point presenttation on the topic
Mathematics power point presenttation on the topicMathematics power point presenttation on the topic
Mathematics power point presenttation on the topic
Meghansh Gautam
 

Ähnlich wie 2 data types and operators in r (20)

2 data structure in R
2 data structure in R2 data structure in R
2 data structure in R
 
Regular expressions in oracle
Regular expressions in oracleRegular expressions in oracle
Regular expressions in oracle
 
UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2UNIX - Class5 - Advance Shell Scripting-P2
UNIX - Class5 - Advance Shell Scripting-P2
 
3 Data Structure in R
3 Data Structure in R3 Data Structure in R
3 Data Structure in R
 
Rcommands-for those who interested in R.
Rcommands-for those who interested in R.Rcommands-for those who interested in R.
Rcommands-for those who interested in R.
 
Python numbers
Python numbersPython numbers
Python numbers
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Module 4- Arrays and Strings
Module 4- Arrays and StringsModule 4- Arrays and Strings
Module 4- Arrays and Strings
 
Statistics lab 1
Statistics lab 1Statistics lab 1
Statistics lab 1
 
Lecture 3 and 4.pptx
Lecture 3 and 4.pptxLecture 3 and 4.pptx
Lecture 3 and 4.pptx
 
vb.net.pdf
vb.net.pdfvb.net.pdf
vb.net.pdf
 
R command cheatsheet.pdf
R command cheatsheet.pdfR command cheatsheet.pdf
R command cheatsheet.pdf
 
@ R reference
@ R reference@ R reference
@ R reference
 
Mathematics power point presenttation on the topic
Mathematics power point presenttation on the topicMathematics power point presenttation on the topic
Mathematics power point presenttation on the topic
 
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
 
1. linear model, inference, prediction
1. linear model, inference, prediction1. linear model, inference, prediction
1. linear model, inference, prediction
 
Nicole
NicoleNicole
Nicole
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
Day 5b statistical functions.pptx
Day 5b   statistical functions.pptxDay 5b   statistical functions.pptx
Day 5b statistical functions.pptx
 

Mehr von Dr Nisha Arora

Mehr von Dr Nisha Arora (14)

1. python for data science
1. python for data science1. python for data science
1. python for data science
 
What do corporates look for in a data science candidate?
What do corporates look for in a data science candidate?What do corporates look for in a data science candidate?
What do corporates look for in a data science candidate?
 
Statistical Inference /Hypothesis Testing
Statistical Inference /Hypothesis Testing Statistical Inference /Hypothesis Testing
Statistical Inference /Hypothesis Testing
 
4 Descriptive Statistics with R
4 Descriptive Statistics with R4 Descriptive Statistics with R
4 Descriptive Statistics with R
 
My talk_ Using data to get business insights
My talk_ Using data to get business insightsMy talk_ Using data to get business insights
My talk_ Using data to get business insights
 
Discriminant analysis using spss
Discriminant analysis using spssDiscriminant analysis using spss
Discriminant analysis using spss
 
7. logistics regression using spss
7. logistics regression using spss7. logistics regression using spss
7. logistics regression using spss
 
Unsupervised learning clustering
Unsupervised learning clusteringUnsupervised learning clustering
Unsupervised learning clustering
 
Cluster analysis using spss
Cluster analysis using spssCluster analysis using spss
Cluster analysis using spss
 
5 mistakes you might be making as a teacher
5 mistakes you might be making as a teacher5 mistakes you might be making as a teacher
5 mistakes you might be making as a teacher
 
Data visualization & Story Telling with Data
Data visualization & Story Telling with DataData visualization & Story Telling with Data
Data visualization & Story Telling with Data
 
1 machine learning demystified
1 machine learning demystified1 machine learning demystified
1 machine learning demystified
 
1 introduction to data science
1 introduction to data science1 introduction to data science
1 introduction to data science
 
1 installing & Getting Started with R
1 installing & Getting Started with R1 installing & Getting Started with R
1 installing & Getting Started with R
 

Kürzlich hochgeladen

Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
amitlee9823
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
amitlee9823
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
amitlee9823
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
amitlee9823
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
karishmasinghjnh
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
amitlee9823
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
only4webmaster01
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
amitlee9823
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
amitlee9823
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
amitlee9823
 

Kürzlich hochgeladen (20)

DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24  Building Real-Time Pipelines With FLaNKDATA SUMMIT 24  Building Real-Time Pipelines With FLaNK
DATA SUMMIT 24 Building Real-Time Pipelines With FLaNK
 
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
(NEHA) Call Girls Katra Call Now 8617697112 Katra Escorts 24x7
 
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night StandCall Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
Call Girls In Bellandur ☎ 7737669865 🥵 Book Your One night Stand
 
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men  🔝Thrissur🔝   Escor...
➥🔝 7737669865 🔝▻ Thrissur Call-girls in Women Seeking Men 🔝Thrissur🔝 Escor...
 
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
Call Girls Jalahalli Just Call 👗 7737669865 👗 Top Class Call Girl Service Ban...
 
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men  🔝mahisagar🔝   Esc...
➥🔝 7737669865 🔝▻ mahisagar Call-girls in Women Seeking Men 🔝mahisagar🔝 Esc...
 
Midocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFxMidocean dropshipping via API with DroFx
Midocean dropshipping via API with DroFx
 
Predicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science ProjectPredicting Loan Approval: A Data Science Project
Predicting Loan Approval: A Data Science Project
 
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
👉 Amritsar Call Girl 👉📞 6367187148 👉📞 Just📲 Call Ruhi Call Girl Phone No Amri...
 
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
Call Girls Bannerghatta Road Just Call 👗 7737669865 👗 Top Class Call Girl Ser...
 
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort ServiceBDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
BDSM⚡Call Girls in Mandawali Delhi >༒8448380779 Escort Service
 
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 7737669865 👗 Top Class Call Girl Service B...
 
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% SecureCall me @ 9892124323  Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
Call me @ 9892124323 Cheap Rate Call Girls in Vashi with Real Photo 100% Secure
 
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
Call Girls Indiranagar Just Call 👗 9155563397 👗 Top Class Call Girl Service B...
 
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 nightCheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
Cheap Rate Call girls Sarita Vihar Delhi 9205541914 shot 1500 night
 
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
Mg Road Call Girls Service: 🍓 7737669865 🍓 High Profile Model Escorts | Banga...
 
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
5CL-ADBA,5cladba, Chinese supplier, safety is guaranteed
 
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
Vip Mumbai Call Girls Marol Naka Call On 9920725232 With Body to body massage...
 
Detecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning ApproachDetecting Credit Card Fraud: A Machine Learning Approach
Detecting Credit Card Fraud: A Machine Learning Approach
 
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
Junnasandra Call Girls: 🍓 7737669865 🍓 High Profile Model Escorts | Bangalore...
 

2 data types and operators in r

  • 1. Dr Nisha Arora Data Types & Operators in R
  • 2. Contents 2 Variable assignment in R Numerical Operators in R In built functions in R Infinity, NA and NAN values in R Atomic data types in R Coercion
  • 3. Variable Assignment in R 3 Variables: Variables are used to store data, which can vary Unique name given to variable (function and objects as well) is known as identifier. To assign value to a variable named ‘x’ x <- value or x = value x <<- value or value -> x or value ->> x
  • 4. Variable Names 4 Some Rules: ✓ An identifier can contain letters, numbers, dots(.) and underscores ( _ ) ✓ It should not have other special characters or blank space in the name ✓ It should not start with a dot followed by a number (eg:- .2iota) ✓ It should not start with an underscore or a number (eg:- _iota or 1more) ✓ It should not be a reserved keyword like for, if, else, in, next, etc. Note: R is case-sensitive
  • 5. Variable Names 5 Not Allowed Allowed monthly salary monthly_salary or monthly.salary or MonthlySalary %growth perc_growth This&that This.that 2ndhighest Second.highest Some Examples:
  • 6. Numerical Operators in R 6 Operator Description + Addition - Subtraction * Multiplication / Division %/% Integer division %% Modulo (estimates remainder in a division) ^ or ** Exponentiation
  • 7. Relational Operators in R 7 Operator Description < Less than <= Less than or equal to > Greater than >= Greater than or equal to == Exactly equal to != Not equal to
  • 8. Logical Operators in R 8 Operator Description x |y Element-wise OR operator x & y Element-wise AND operator ! x Not Operator X || y Takes only first element of iterables X && y Takes only first element of iterables
  • 9. Inbuilt Mathematical Functions 9 pi; exp(1) log(x) # log to base e of x log10(x) # log to base 10 of x log(x,n) # log to base n of x floor(x) # greatest integer <x ceiling(x) # smallest integer >x lgamma(x) # natural log of gamma (x) choose(n,x) # Binomial coefficient nCx sqrt(x); factorial(x); gamma(x)
  • 10. Inbuilt Mathematical Functions 10 trunc(x) # closest integer to x between x and 0 E.g., trunc(1.5) =1, trunc(-1.5) = -1 NOTE: trunc is like floor for positive values and like ceiling for negative values round(x, digits=0) # round the value of x to an integer signif(x, digits=6) # give x to 6 digits in scientific notation runif(n) # generates n random numbers between 0 and 1 from a uniform distribution
  • 11. Inbuilt Trigonometrically Functions 11 cos(x) # cosine of x in radians sin(x) # sine of x in radians tan(x) # tangent of x in radians acos(x), asin(x), atan(x) # inverse trigonometric transformations of real or complex numbers acosh(x), asinh(x), atanh(x) # inverse hyperbolic trigonometric transformations of real or complex numbers abs(x) # the absolute value of x, ignoring the minus sign if there is one
  • 12. 12 Data types in R ✓ Logical, for example, TRUE, FALSE ✓ Numeric (sometimes called double, usually treated as floating point number/real number), for example, 11.7, -3, 99.0, 1000 ✓ Integer, for example, 25L, 0L, -33L Specify L suffix to get integer (i.e. 1L gives integer 1) ✓ Complex, for example, 3 – 4i, 4+5i ✓ Character, for example, “abc”, “34”, “TRUE”, “3-4i”, ‘3L’
  • 13. 13 Data types in R ✓ To check the class of variables, class() command can be used For example: class(7); class(7L); class(T); class(‘T’); class(3+0i) ✓ Special numbers such as Inf and NAN are of numeric class For example: class(8/0); class(0/0)
  • 14. 14 Coercion All elements of a vector must be the same type, so when we attempt to combine different types they will be coerced to the most flexible type. Types from least to most flexible are: . Logical Integer Double/ Numeric Complex Character
  • 15. 15 Coercion When a logical vector is coerced to an integer or double, TRUE becomes 1 and FALSE becomes 0 x <- c(FALSE, FALSE, TRUE); as.numeric(x) Total number of TRUEs sum(x) Proportion that are TRUE mean(x)
  • 16. 16 Coercion in R ✓ To forcefully coerce a variable class into other, following functions are used as.numeric(), as.logical(), etc. In Python, we call it ‘typecasting’ https://youtu.be/FJ6IkFycCdA
  • 17. 17 NA’s and NAN’s in R Inf Infinity NA Not available, generally interpreted as a missing value The default type of NA is logical, unless coerced to some other type, so the appearance of a missing value may trigger logical rather than numeric indexing. Numeric and logical calculations with NA generally return NA. NAN Not a number, e.g., 0/0
  • 18. 18 NA’s and NAN’s in R ✓ is.nan() is used to test for NaN's ✓ is.na() is used to test, if objects are NA's ✓ A NAN value can also be NA but not conversely. ✓ It means is.na also returns TRUE for NaN’s ✓ Functions like mean() and sum() on vector containing NA or NaN, they will return NA and NaN. ✓ This behavior alerts you to the presence of the bad value.
  • 19. 19 NULL in R ✓ NULL is different from the NA and NAN ✓ NULL means that there is no value, while NA and NaN mean that there is some value, although one that is perhaps not usable. ✓ is.null() is used to test for NULL ✓ Functions like mean() and sum() on vector containing NULL doesn’t pose any issue as NULL value simply doesn’t exists
  • 20. 20 Data Type Conversions Use is.foo to test for data type foo. Returns TRUE or FALSE Use as.foo to explicitly convert it. Examples: is.numeric(), is.character(), is.vector(), is.matrix(), is.data.frame() as.numeric(), as.character(), as.vector(), as.matrix(), as.data.frame)
  • 21. 21 Handling of missing values X <- c(1:8,NA) ✓ Removing missing vlaues mean(X, na.rm = T) or mean(X ,na.rm=TRUE) ✓ To check for the location of missing values within a vector which(is.na(X)) ✓ To assign this a large number, say, 999 X[which(is.na(X))] = 999
  • 22. 22 Handling of missing values x <- c(1, 2, NA, 4, NA, 5) ✓ Identify missing values bad <- is.na(x) ✓ To remove missing values x[!bad]
  • 23. 23 Handling of missing values x <- c(1, 2, NA, 4, NA, 5); y <- c("a", "b", NA, "d", "e", NA) df = data.frame(x,y) ✓ To take the subset of data frame with no missing value good = complete.cases(x,y); good ✓ To take the subset of vector x with no missing value x[good] ✓ To take the subset of vector y with no missing value y[good]
  • 24. Function Composition Pipe Operator https://www.linkedin.com/posts/drnishaarora_programming-r-rstats-activity-6783610405076914176-23p- https://github.com/arora123/R-for-Data-Science/blob/master/pipe%20operator%20in%20R.R
  • 25. Books 25 ✓ Crowley, M. J. (2007). The R Book. Chichester, New England: John Wiley & Sons, Ltd. ✓ An Introduction to R by W. N. Venables, D. M. Smith and the R Core Team ✓ R in a Nutshell by Joseph Adler: O’Reilly ✓ Teetor, P. (2011). R cookbook. Sebastopol, CA: O’Reilly Media Inc.
  • 26. Books 26 ✓ Bio Statistics - https://www.middleprofessor.com/files/applied- biostatistics_bookdown/_book/ ✓ Advanced R - https://adv-r.hadley.nz/ ✓ Data Visualization - https://rkabacoff.github.io/datavis/ ✓ R for Data Science - https://r4ds.had.co.nz/index.html ✓ Data Exploration & Analysis - https://bookdown.org/mikemahoney218/IDEAR/ ✓ https://bookdown.org/mikemahoney218/LectureBook/
  • 29. 29 Reach Out to Me http://stats.stackexchange.com/users/79100/learner https://www.researchgate.net/profile/Nisha_Arora2/contributions https://www.quora.com/profile/Nisha-Arora-9 https://github.com/arora123/ https://www.youtube.com/channel/UCniyhvrD_8AM2jXki3eEErw https://www.linkedin.com/in/drnishaarora/ Dr.aroranisha@gmail.com