SlideShare a Scribd company logo
r-squared
Slide 1 www.r-squared.in/rprogramming
R Programming
Learn the fundamentals of data analysis with R.
r-squared
Slide 2
Course Modules
www.r-squared.in/rprogramming
✓ Introduction
✓ Elementary Programming
✓ Working With Data
✓ Selection Statements
✓ Loops
✓ Functions
✓ Debugging
✓ Unit Testing
r-squared
Slide 3
Working With Data
www.r-squared.in/rprogramming
✓ Data Types
✓ Data Structures
✓ Data Creation
✓ Data Info
✓ Data Subsetting
✓ Comparing R Objects
✓ Importing Data
✓ Exporting Data
✓ Data Transformation
✓ Numeric Functions
✓ String Functions
✓ Mathematical Functions
r-squared
In this unit, we will explore the following numeric functions:
Slide 4
Numeric Functions
www.r-squared.in/rprogramming
● signif()
● jitter()
● format()
● formatC()
● abs()
● round()
● ceiling()
● floor()
r-squared
Slide 5
abs()
www.r-squared.in/rprogramming
Description
abs() computes the absolute values of its arguments.
Syntax
abs(x)
Returns
Absolute value
Documentation
help(abs)
r-squared
Slide 6
abs()
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- -5
> abs(x)
[1] 5
> # example 2
> y <- 5
> abs(y)
[1] 5
> # example 3
> z <- c(1, -3, 4, -7, 5, -9)
> abs(z)
[1] 1 3 4 7 5 9
r-squared
Slide 7
round()
www.r-squared.in/rprogramming
Description
round() rounds its argument to the specified number of decimal places.
Syntax
round(x, digits)
Returns
Argument rounded to specified number of decimal places.
Documentation
help(round)
r-squared
Slide 8
round()
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- 5.3645
> round(x) # zero decimal values
[1] 5
> round(x, digits = 1) # one decimal values
[1] 5.4
> round(x, digits = 2) # two decimal values
[1] 5.36
> round(x, digits = 3) # three decimal values
[1] 5.364
r-squared
Slide 9
ceiling()
www.r-squared.in/rprogramming
Description
ceiling() takes a numeric argument x and returns the smallest integer not less than x.
Syntax
ceiling(x)
Returns
Integer
Documentation
help(ceiling)
r-squared
Slide 10
ceiling()
www.r-squared.in/rprogramming
Examples
> example 1
> x <- 5.3645
> ceiling(x)
[1] 6
> example 2
> x <- 3.94
> ceiling(x)
[1] 4
> example 3
> x
[1] 7.012865 8.148132 9.840098 2.965393 2.098276 6.139226 3.819461 8.849482 1.068249
[10] 5.105874
> ceiling(x)
[1] 8 9 10 3 3 7 4 9 2 6
r-squared
Slide 11
floor()
www.r-squared.in/rprogramming
Description
floor() takes a numeric argument x and returns the smallest integer not greater than x.
Syntax
floor(..., collapse = NULL)
Returns
Integer
Documentation
help(floor)
r-squared
Slide 12
floor()
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- 5.3645
> floor(x)
[1] 5
> # example 2
> x <- 3.94
> floor(x)
[1] 3
> # example 3
> x <- sample(jitter(1:10))
> x
[1] 6.1581438 9.9260513 0.9823364 4.1083687 4.9102557 8.1316709 7.0094556 2.8870083
[9] 2.1403249 9.0941759
> floor(x)
[1] 6 9 0 4 4 8 7 2 2 9
r-squared
Slide 13
trunc()
www.r-squared.in/rprogramming
Description
trunc() takes a numeric argument and returns the first integer as the values is truncated
towards zero.
Syntax
trunc(x)
Returns
Integer
Documentation
help(trunc)
r-squared
Slide 14
trunc()
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- 5.3645
> trunc(x)
[1] 5
# as we truncate the value in x towards zero, the first integer that appears is 5.
> # example 2
> x <- -3.94
> trunc(x)
[1] -3
> round(x)
[1] -4
> floor(x)
[1] -4
# as we truncate the value in x towards zero, the first integer that appears is -3.
r-squared
Slide 15
signif()
www.r-squared.in/rprogramming
Description
signif() rounds the value in the first argument to the specified number of significant
digits.
Syntax
signif(x, digits)
Returns
Value with specified number of significant digits
Documentation
help(signif)
r-squared
Slide 16
signif()
www.r-squared.in/rprogramming
Examples
> # example
> x <- 5.3645
> signif(x, 1)
[1] 5
> signif(x, 2)
[1] 5.4
> signif(x, 3)
[1] 5.36
r-squared
Slide 17
jitter()
www.r-squared.in/rprogramming
Description
jitter() add noise to a numeric vector.
Syntax
jitter(numeric_vector)
Returns
Numeric vector with noise
Documentation
help(jitter)
r-squared
Slide 18
jitter()
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- 1:10
> x
[1] 1 2 3 4 5 6 7 8 9 10
> jitter(x)
[1] 1.198246 1.845626 3.171562 3.809923 5.188604 6.171728 7.022194 8.058092
[9] 9.150582 10.142704
r-squared
Slide 19
format()
www.r-squared.in/rprogramming
Description
format() will format an R object for pretty printing.
Syntax
format(x, digits, nsmall, justify)
Returns
Formatted object
Documentation
help(format)
r-squared
Slide 20
format()
www.r-squared.in/rprogramming
Examples
> # example 1
> x
[1] 1.187272 2.080868 3.197517 4.016246 4.979482 6.163807 6.837692 8.013903 8.864735
[10] 9.939144
> format(x, digits = 3)
[1] "1.19" "2.08" "3.20" "4.02" "4.98" "6.16" "6.84" "8.01" "8.86" "9.94"
> # example 2
> x <- 1:10
> format(x)
[1] " 1" " 2" " 3" " 4" " 5" " 6" " 7" " 8" " 9" "10"
> format(x, trim = TRUE)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
r-squared
Slide 21
format()
www.r-squared.in/rprogramming
Examples
> # example 3
> format(6.5)
[1] "6.5"
> format(6.5, nsmall = 3)
[1] "6.500"
> format(c(6.5, 15.3), digits = 2)
[1] " 6.5" "15.3"
> format(c(6.5, 15.3), digits = 2, nsmall = 1)
[1] " 6.5" "15.3"
r-squared
Slide 22
formatC()
www.r-squared.in/rprogramming
Description
formatC() formats numbers individually and flexibly.
Syntax
formatC(x, digits, width)
Returns
Formatted object
Documentation
help(formatC)
r-squared
Slide 23
formatC()
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- 1:10
> formatC(x)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
> formatC(x, width = 6)
[1] " 1" " 2" " 3" " 4" " 5" " 6" " 7" " 8" " 9"
[10] " 10"
> # example 2
> x <- sample(jitter(1:10))
> x
[1] 7.0094486 0.9592379 5.8403164 8.8848952 4.9665959 9.9507841 3.1295332 7.8283830
[9] 2.1360850 3.8991551
> formatC(x, digits = 4)
[1] "7.009" "0.9592" " 5.84" "8.885" "4.967" "9.951" " 3.13" "7.828" "2.136"
[10] "3.899"
r-squared
In the next unit, we will explore string manipulation in R using the following functions:
Slide 24
Next Steps...
www.r-squared.in/rprogramming
● match()
● char.expand()
● grep()
● grepl()
● sub()
● substr()
● substring()
● strsplit()
● strtrim()
● chartr()
● tolower()
● toupper()
● toString()
● nchar()
● nzchar()
● noquote()
● pmatch()
● charmatch()
r-squared
Slide 25
Connect With Us
www.r-squared.in/rprogramming
Visit r-squared for tutorials
on:
● R Programming
● Business Analytics
● Data Visualization
● Web Applications
● Package Development
● Git & GitHub

More Related Content

What's hot (20)

PDF
Data transformation-cheatsheet
Dieudonne Nahigombeye
 
PDF
Stata cheat sheet: data processing
Tim Essam
 
PDF
Stata Programming Cheat Sheet
Laura Hughes
 
PDF
Data import-cheatsheet
Dieudonne Nahigombeye
 
PDF
Stata cheatsheet transformation
Laura Hughes
 
PDF
Stata cheat sheet: data transformation
Tim Essam
 
PDF
Hive function-cheat-sheet
Dr. Volkan OBAN
 
PDF
Dplyr and Plyr
Paul Richards
 
PPT
Arrays in SAS
guest2160992
 
PDF
R factors
Learnbay Datascience
 
PDF
Introduction to data.table in R
Paul Richards
 
PPTX
Data Management in Python
Sankhya_Analytics
 
PPT
Stack queue
Harry Potter
 
PDF
Stata cheat sheet analysis
Tim Essam
 
PDF
Pandas Cheat Sheet
ACASH1011
 
PDF
5 R Tutorial Data Visualization
Sakthi Dasans
 
PPTX
Oracle Database 12c - Introducing SQL Pattern Recognition through MATCH_RECOG...
Lucas Jellema
 
PPT
Chapter 6 arrays part-1
Synapseindiappsdevelopment
 
PDF
Morel, a Functional Query Language
Julian Hyde
 
Data transformation-cheatsheet
Dieudonne Nahigombeye
 
Stata cheat sheet: data processing
Tim Essam
 
Stata Programming Cheat Sheet
Laura Hughes
 
Data import-cheatsheet
Dieudonne Nahigombeye
 
Stata cheatsheet transformation
Laura Hughes
 
Stata cheat sheet: data transformation
Tim Essam
 
Hive function-cheat-sheet
Dr. Volkan OBAN
 
Dplyr and Plyr
Paul Richards
 
Arrays in SAS
guest2160992
 
Introduction to data.table in R
Paul Richards
 
Data Management in Python
Sankhya_Analytics
 
Stack queue
Harry Potter
 
Stata cheat sheet analysis
Tim Essam
 
Pandas Cheat Sheet
ACASH1011
 
5 R Tutorial Data Visualization
Sakthi Dasans
 
Oracle Database 12c - Introducing SQL Pattern Recognition through MATCH_RECOG...
Lucas Jellema
 
Chapter 6 arrays part-1
Synapseindiappsdevelopment
 
Morel, a Functional Query Language
Julian Hyde
 

Viewers also liked (20)

PPTX
R programming
Shantanu Patil
 
PPTX
R Programming: Variables & Data Types
Rsquared Academy
 
PPTX
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
PPTX
Variables in matlab
TUOS-Sam
 
DOCX
Matlab time series example
Ovie Uddin Ovie Uddin
 
PDF
metode numerik stepest descent dengan rerata aritmatika
Sabarinsyah Piliang
 
PPTX
Introduction to Matlab Scripts
Shameer Ahmed Koya
 
PPT
Loops in matlab
TUOS-Sam
 
PDF
Modul1 metode bagi dua Praktikum Metode Numerik
James Montolalu
 
PDF
Modul2 metode regula falsi praktikum metode numerik
James Montolalu
 
PPTX
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
PPT
Fungsi grafik di matlab
UNISKA, SMK Telkom Banjarbaru
 
PPTX
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
PDF
Metode numerik-buku-ajar-unila
Ibad Ahmad
 
PPTX
Band Combination of Landsat 8 Earth-observing Satellite Images
Kabir Uddin
 
PPTX
Matlab 1 level_1
Ahmed Farouk
 
PPTX
MATLAB Programming - Loop Control Part 2
Shameer Ahmed Koya
 
PPTX
mat lab introduction and basics to learn
pavan373
 
PDF
Panduan matlab
giya12001
 
PPT
Metode numerik persamaan non linier
Izhan Nassuha
 
R programming
Shantanu Patil
 
R Programming: Variables & Data Types
Rsquared Academy
 
CIV1900 Matlab - Plotting & Coursework
TUOS-Sam
 
Variables in matlab
TUOS-Sam
 
Matlab time series example
Ovie Uddin Ovie Uddin
 
metode numerik stepest descent dengan rerata aritmatika
Sabarinsyah Piliang
 
Introduction to Matlab Scripts
Shameer Ahmed Koya
 
Loops in matlab
TUOS-Sam
 
Modul1 metode bagi dua Praktikum Metode Numerik
James Montolalu
 
Modul2 metode regula falsi praktikum metode numerik
James Montolalu
 
User defined Functions in MATLAB Part 1
Shameer Ahmed Koya
 
Fungsi grafik di matlab
UNISKA, SMK Telkom Banjarbaru
 
User Defined Functions in MATLAB Part-4
Shameer Ahmed Koya
 
Metode numerik-buku-ajar-unila
Ibad Ahmad
 
Band Combination of Landsat 8 Earth-observing Satellite Images
Kabir Uddin
 
Matlab 1 level_1
Ahmed Farouk
 
MATLAB Programming - Loop Control Part 2
Shameer Ahmed Koya
 
mat lab introduction and basics to learn
pavan373
 
Panduan matlab
giya12001
 
Metode numerik persamaan non linier
Izhan Nassuha
 
Ad

Similar to R Programming: Numeric Functions In R (20)

PDF
R Programming: Mathematical Functions In R
Rsquared Academy
 
PPT
R Programming Intro
062MayankSinghal
 
PDF
Introduction to R programming
Alberto Labarga
 
PPTX
BA lab1.pptx
sherifsalem24
 
PPTX
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
PPTX
R Basics
Dr.E.N.Sathishkumar
 
PDF
[1062BPY12001] Data analysis with R / week 2
Kevin Chun-Hsien Hsu
 
PDF
R Programming: Comparing Objects In R
Rsquared Academy
 
PPTX
Ggplot2 v3
Josh Doyle
 
PDF
BUilt in Functions and Simple programs in R.pdf
karthikaparthasarath
 
PPT
Loops and functions in r
manikanta361
 
PPTX
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
PPTX
statistical computation using R- an intro..
Kamarudheen KV
 
PPTX
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
PPTX
世预赛买球-世预赛买球竞彩平台-世预赛买球竞猜平台|【​网址​🎉ac123.net🎉​】
hanniaarias53
 
PPTX
美洲杯买球-美洲杯买球怎么押注-美洲杯买球押注怎么玩|【​网址​🎉ac99.net🎉​】
kokoparmod677
 
PPTX
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
lopezkatherina914
 
PPTX
世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】
bljeremy734
 
PPTX
欧洲杯足彩-欧洲杯足彩线上体育买球-欧洲杯足彩买球推荐网站|【​网址​🎉ac55.net🎉​】
brunasordi905
 
PPTX
欧洲杯下注-欧洲杯下注买球网-欧洲杯下注买球网站|【​网址​🎉ac10.net🎉​】
brendonbrash97589
 
R Programming: Mathematical Functions In R
Rsquared Academy
 
R Programming Intro
062MayankSinghal
 
Introduction to R programming
Alberto Labarga
 
BA lab1.pptx
sherifsalem24
 
Unit I - 1R introduction to R program.pptx
SreeLaya9
 
[1062BPY12001] Data analysis with R / week 2
Kevin Chun-Hsien Hsu
 
R Programming: Comparing Objects In R
Rsquared Academy
 
Ggplot2 v3
Josh Doyle
 
BUilt in Functions and Simple programs in R.pdf
karthikaparthasarath
 
Loops and functions in r
manikanta361
 
R1-Intro (2udsjhfkjdshfkjsdkfhsdkfsfsffs
sabari Giri
 
statistical computation using R- an intro..
Kamarudheen KV
 
世预赛买球-世预赛买球比赛投注-世预赛买球比赛投注官网|【​网址​🎉ac10.net🎉​】
bljeremy734
 
世预赛买球-世预赛买球竞彩平台-世预赛买球竞猜平台|【​网址​🎉ac123.net🎉​】
hanniaarias53
 
美洲杯买球-美洲杯买球怎么押注-美洲杯买球押注怎么玩|【​网址​🎉ac99.net🎉​】
kokoparmod677
 
欧洲杯体彩-欧洲杯体彩比赛投注-欧洲杯体彩比赛投注官网|【​网址​🎉ac99.net🎉​】
lopezkatherina914
 
世预赛投注-世预赛投注投注官网app-世预赛投注官网app下载|【​网址​🎉ac123.net🎉​】
bljeremy734
 
欧洲杯足彩-欧洲杯足彩线上体育买球-欧洲杯足彩买球推荐网站|【​网址​🎉ac55.net🎉​】
brunasordi905
 
欧洲杯下注-欧洲杯下注买球网-欧洲杯下注买球网站|【​网址​🎉ac10.net🎉​】
brendonbrash97589
 
Ad

More from Rsquared Academy (20)

PDF
Handling Date & Time in R
Rsquared Academy
 
PDF
Market Basket Analysis in R
Rsquared Academy
 
PDF
Practical Introduction to Web scraping using R
Rsquared Academy
 
PDF
Joining Data with dplyr
Rsquared Academy
 
PDF
Explore Data using dplyr
Rsquared Academy
 
PDF
Data Wrangling with dplyr
Rsquared Academy
 
PDF
Writing Readable Code with Pipes
Rsquared Academy
 
PDF
Introduction to tibbles
Rsquared Academy
 
PDF
Read data from Excel spreadsheets into R
Rsquared Academy
 
PDF
Read/Import data from flat/delimited files into R
Rsquared Academy
 
PDF
Variables & Data Types in R
Rsquared Academy
 
PDF
How to install & update R packages?
Rsquared Academy
 
PDF
How to get help in R?
Rsquared Academy
 
PDF
Introduction to R
Rsquared Academy
 
PDF
R Markdown Tutorial For Beginners
Rsquared Academy
 
PDF
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
PDF
R Programming: Introduction to Matrices
Rsquared Academy
 
PDF
R Programming: Introduction to Vectors
Rsquared Academy
 
PDF
Data Visualization With R: Learn To Combine Multiple Graphs
Rsquared Academy
 
PDF
R Data Visualization: Learn To Add Text Annotations To Plots
Rsquared Academy
 
Handling Date & Time in R
Rsquared Academy
 
Market Basket Analysis in R
Rsquared Academy
 
Practical Introduction to Web scraping using R
Rsquared Academy
 
Joining Data with dplyr
Rsquared Academy
 
Explore Data using dplyr
Rsquared Academy
 
Data Wrangling with dplyr
Rsquared Academy
 
Writing Readable Code with Pipes
Rsquared Academy
 
Introduction to tibbles
Rsquared Academy
 
Read data from Excel spreadsheets into R
Rsquared Academy
 
Read/Import data from flat/delimited files into R
Rsquared Academy
 
Variables & Data Types in R
Rsquared Academy
 
How to install & update R packages?
Rsquared Academy
 
How to get help in R?
Rsquared Academy
 
Introduction to R
Rsquared Academy
 
R Markdown Tutorial For Beginners
Rsquared Academy
 
R Data Visualization Tutorial: Bar Plots
Rsquared Academy
 
R Programming: Introduction to Matrices
Rsquared Academy
 
R Programming: Introduction to Vectors
Rsquared Academy
 
Data Visualization With R: Learn To Combine Multiple Graphs
Rsquared Academy
 
R Data Visualization: Learn To Add Text Annotations To Plots
Rsquared Academy
 

Recently uploaded (20)

PPTX
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
PDF
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
PDF
apidays Helsinki & North 2025 - How (not) to run a Graphql Stewardship Group,...
apidays
 
PDF
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
PDF
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
PDF
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
PPTX
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
PPTX
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
PDF
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
PDF
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
PDF
apidays Singapore 2025 - Streaming Lakehouse with Kafka, Flink and Iceberg by...
apidays
 
PDF
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
PDF
Data Science Course Certificate by Sigma Software University
Stepan Kalika
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PDF
Optimizing Large Language Models with vLLM and Related Tools.pdf
Tamanna36
 
PDF
NIS2 Compliance for MSPs: Roadmap, Benefits & Cybersecurity Trends (2025 Guide)
GRC Kompas
 
PDF
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna36
 
apidays Helsinki & North 2025 - Running a Successful API Program: Best Practi...
apidays
 
apidays Singapore 2025 - How APIs can make - or break - trust in your AI by S...
apidays
 
apidays Helsinki & North 2025 - How (not) to run a Graphql Stewardship Group,...
apidays
 
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
apidays Singapore 2025 - From API Intelligence to API Governance by Harsha Ch...
apidays
 
apidays Helsinki & North 2025 - Agentic AI: A Friend or Foe?, Merja Kajava (A...
apidays
 
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
apidays Singapore 2025 - The API Playbook for AI by Shin Wee Chuang (PAND AI)
apidays
 
Driving Employee Engagement in a Hybrid World.pdf
Mia scott
 
apidays Singapore 2025 - Streaming Lakehouse with Kafka, Flink and Iceberg by...
apidays
 
apidays Singapore 2025 - Building a Federated Future, Alex Szomora (GSMA)
apidays
 
Data Science Course Certificate by Sigma Software University
Stepan Kalika
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
Optimizing Large Language Models with vLLM and Related Tools.pdf
Tamanna36
 
NIS2 Compliance for MSPs: Roadmap, Benefits & Cybersecurity Trends (2025 Guide)
GRC Kompas
 
Simplifying Document Processing with Docling for AI Applications.pdf
Tamanna36
 

R Programming: Numeric Functions In R