SlideShare a Scribd company logo
1 of 11
Useful Functions in R
Anil Goyal
2022-06-23
SOME USEFUL FUNCTIONS
Common Mathematical Operators in R
Operator/ function Meaning Example
+ Addition 4+5 is 9
- Substraction 4-5 is -1
* Multiplication 4*5 is 20
/ Division 4/5 is 0.8
^ Exponent 2^4 is 16
%% Modulus (Remainder from division) 15 %% 12 is 3
%/% Integer Division 15 %/% 12 is 1
logical operators -1
Operator/ function Meaning Example
== Is RHS equal to LHS? 5 == 2 will return FALSE
'Anil' == 'anil' is FALSE
!= Is RHS not equal to LHS? 'ABCD' != 'abcd' is TRUE
>= Is LHS greater than or equal to RHS? 5 >= 2 will return TRUE
<= Is LHS less than or equal to RHS? 15 <= 2 will return FALSE
> Is LHS strictly greater than RHS? 2 > 2 will return FALSE
logical operators -2
Operator/ function Meaning Example
< Is LHS strictly less than RHS? 12 < 12 will return FALSE
is.na() Whether the argument passed is NA is.na(NA) is TRUE
is.null() Whether the argument passed is
null
is.null(NA) is FALSE
| Logical OR TRUE | FALSE will return TRUE
& Logical AND TRUE & FALSE will return FALSE
! Logical NOT !TRUE will return FALSE
logical operators -3
Operator/ function Meaning Example
|| Element wise Logical OR Examines only the first element of
the operands resulting into a single
length logical vector
&& Element wise Logical AND Examines only the first element of
the operands resulting into a single
length logical vector
%in% LHS IN RHS Checks whether LHS elements are
present in RHS vector
Common arithmetical Functions
Function Meaning Input Output
sum() Adds all elements One or more Vector,
matrix, array
Vector having 1 element
only
prod() Returns product of all
elements
One or more Vector,
matrix, array
Vector having 1 element
only
mean() Returns the arithmetic
mean
One Vector, matrix, array Vector having 1 element
only
max() Returns maximum value One or more Vector,
matrix, array
Vector having 1 element
only
min() Returns minimum value One or more Vector,
matrix, array
Vector having 1 element
only
More arithmetical Functions
Function Meaning Input Output
ceiling() Returns integer(s) not less
than given values
One Vector, matrix, array Vector, matrix, array
having same dim
floor() Returns largest integers
not greater than given
values
One Vector, matrix, array Vector, matrix, array
having same dim
trunc() returns integers formed by
truncating the values
towards 0
One Vector, matrix, array Vector, matrix, array
having same dim
round(x, digits =
0)
Rounds the given value(s)
to number of decimal
places provided
One Vector, matrix, array Vector, matrix, array
having same dim
More arithmetical Functions
Function Meaning Input Output
signif(x, digits =
6)
Round to significant
digits
One Vector, matrix, array Vector, matrix, array
having same dim
factorial() Returns factorial One Vector, matrix, array
of integer type
Vector having 1 element
sqrt() Returns square root One Vector, matrix, array Vector, matrix, array
having same dim
log10() or log2() Logrithm with base 10 or 2
respectively
One Vector, matrix, array Vector, matrix, array
having same dim
exp(x) returns exponential One Vector, matrix, array Vector, matrix, array
having same dim
Some Statistical functions
Function Meaning Input Output
sd() Returns standard
deviation
One Vector, matrix, array Vector having 1 element
only
var() Returns variance One or more Vector,
matrix, array
Vector having 1 element
only
median() Returns median value One Vector, matrix, array Vector having 1 element
only
range() Returns range One Vector, matrix, array Vector having 2 elements
More Statistical functions
Function Meaning Input Output
IQR() Computes interquartile
range of the x values
One Vector, matrix, array Vector having 1 element
only
quantile() Computes percentile of
given values for the given
probabilities in probs
argument
One Vector, matrix, array Named Vector having 5
elements by default, OR
equal to the length of
probs vector given

More Related Content

Similar to R-Prog-Functions.pptx

Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
ammarqazi53
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
stopgolook
 

Similar to R-Prog-Functions.pptx (20)

C Sharp Jn (2)
C Sharp Jn (2)C Sharp Jn (2)
C Sharp Jn (2)
 
Functional Programming Advanced
Functional Programming AdvancedFunctional Programming Advanced
Functional Programming Advanced
 
Report Group 4 Constants and Variables
Report Group 4 Constants and VariablesReport Group 4 Constants and Variables
Report Group 4 Constants and Variables
 
Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)Report Group 4 Constants and Variables(TLE)
Report Group 4 Constants and Variables(TLE)
 
Introduction to DAX Language
Introduction to DAX LanguageIntroduction to DAX Language
Introduction to DAX Language
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptxEPE821_Lecture3.pptx
EPE821_Lecture3.pptx
 
Intro to relational model
Intro to relational modelIntro to relational model
Intro to relational model
 
354 ch6
354 ch6354 ch6
354 ch6
 
Chapter6
Chapter6Chapter6
Chapter6
 
Hive function-cheat-sheet
Hive function-cheat-sheetHive function-cheat-sheet
Hive function-cheat-sheet
 
Lesson 2.1 what is a function
Lesson 2.1    what is a functionLesson 2.1    what is a function
Lesson 2.1 what is a function
 
Operators
OperatorsOperators
Operators
 
Basics of c++
Basics of c++ Basics of c++
Basics of c++
 
5815248.ppt
5815248.ppt5815248.ppt
5815248.ppt
 
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
Applications of ICT Lecture 3.pptxjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj...
 
Programming
ProgrammingProgramming
Programming
 
Map, Reduce and Filter in Swift
Map, Reduce and Filter in SwiftMap, Reduce and Filter in Swift
Map, Reduce and Filter in Swift
 
Python programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operationsPython programming: Anonymous functions, String operations
Python programming: Anonymous functions, String operations
 
Python programming for Beginners - II
Python programming for Beginners - IIPython programming for Beginners - II
Python programming for Beginners - II
 
Java Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdfJava Code The traditional way to deal with these in Parsers is the .pdf
Java Code The traditional way to deal with these in Parsers is the .pdf
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 
Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
Choosing the Right FDO Deployment Model for Your Application _ Geoffrey at In...
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdfSimplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
Simplified FDO Manufacturing Flow with TPMs _ Liam at Infineon.pdf
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
The Metaverse: Are We There Yet?
The  Metaverse:    Are   We  There  Yet?The  Metaverse:    Are   We  There  Yet?
The Metaverse: Are We There Yet?
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Buy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdfBuy Epson EcoTank L3210 Colour Printer Online.pdf
Buy Epson EcoTank L3210 Colour Printer Online.pdf
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 

R-Prog-Functions.pptx

  • 1. Useful Functions in R Anil Goyal 2022-06-23
  • 3. Common Mathematical Operators in R Operator/ function Meaning Example + Addition 4+5 is 9 - Substraction 4-5 is -1 * Multiplication 4*5 is 20 / Division 4/5 is 0.8 ^ Exponent 2^4 is 16 %% Modulus (Remainder from division) 15 %% 12 is 3 %/% Integer Division 15 %/% 12 is 1
  • 4. logical operators -1 Operator/ function Meaning Example == Is RHS equal to LHS? 5 == 2 will return FALSE 'Anil' == 'anil' is FALSE != Is RHS not equal to LHS? 'ABCD' != 'abcd' is TRUE >= Is LHS greater than or equal to RHS? 5 >= 2 will return TRUE <= Is LHS less than or equal to RHS? 15 <= 2 will return FALSE > Is LHS strictly greater than RHS? 2 > 2 will return FALSE
  • 5. logical operators -2 Operator/ function Meaning Example < Is LHS strictly less than RHS? 12 < 12 will return FALSE is.na() Whether the argument passed is NA is.na(NA) is TRUE is.null() Whether the argument passed is null is.null(NA) is FALSE | Logical OR TRUE | FALSE will return TRUE & Logical AND TRUE & FALSE will return FALSE ! Logical NOT !TRUE will return FALSE
  • 6. logical operators -3 Operator/ function Meaning Example || Element wise Logical OR Examines only the first element of the operands resulting into a single length logical vector && Element wise Logical AND Examines only the first element of the operands resulting into a single length logical vector %in% LHS IN RHS Checks whether LHS elements are present in RHS vector
  • 7. Common arithmetical Functions Function Meaning Input Output sum() Adds all elements One or more Vector, matrix, array Vector having 1 element only prod() Returns product of all elements One or more Vector, matrix, array Vector having 1 element only mean() Returns the arithmetic mean One Vector, matrix, array Vector having 1 element only max() Returns maximum value One or more Vector, matrix, array Vector having 1 element only min() Returns minimum value One or more Vector, matrix, array Vector having 1 element only
  • 8. More arithmetical Functions Function Meaning Input Output ceiling() Returns integer(s) not less than given values One Vector, matrix, array Vector, matrix, array having same dim floor() Returns largest integers not greater than given values One Vector, matrix, array Vector, matrix, array having same dim trunc() returns integers formed by truncating the values towards 0 One Vector, matrix, array Vector, matrix, array having same dim round(x, digits = 0) Rounds the given value(s) to number of decimal places provided One Vector, matrix, array Vector, matrix, array having same dim
  • 9. More arithmetical Functions Function Meaning Input Output signif(x, digits = 6) Round to significant digits One Vector, matrix, array Vector, matrix, array having same dim factorial() Returns factorial One Vector, matrix, array of integer type Vector having 1 element sqrt() Returns square root One Vector, matrix, array Vector, matrix, array having same dim log10() or log2() Logrithm with base 10 or 2 respectively One Vector, matrix, array Vector, matrix, array having same dim exp(x) returns exponential One Vector, matrix, array Vector, matrix, array having same dim
  • 10. Some Statistical functions Function Meaning Input Output sd() Returns standard deviation One Vector, matrix, array Vector having 1 element only var() Returns variance One or more Vector, matrix, array Vector having 1 element only median() Returns median value One Vector, matrix, array Vector having 1 element only range() Returns range One Vector, matrix, array Vector having 2 elements
  • 11. More Statistical functions Function Meaning Input Output IQR() Computes interquartile range of the x values One Vector, matrix, array Vector having 1 element only quantile() Computes percentile of given values for the given probabilities in probs argument One Vector, matrix, array Named Vector having 5 elements by default, OR equal to the length of probs vector given