SlideShare a Scribd company logo
1 of 24
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 mathematical functions:
Slide 4
Mathematical Functions
www.r-squared.in/rprogramming
● Arithmetic Operators
● Column/ Row Operators
● Cumulative Operators
● Sampling
● Set Operations
● Logarithm
r-squared
Slide 5
Arithmetic Operators
www.r-squared.in/rprogramming
Operator Description
+ Addition
- Subtraction
* Multiplication
/ Division
^ Exponential
%% Modulus
%/% Integer division
r-squared
Slide 6
Arithmetic Operators
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- 5
> y <- 2
> x + y
[1] 7
> x - y
[1] 3
> x * y
[1] 10
> x / y
[1] 2.5
r-squared
Slide 7
Arithmetic Operators
www.r-squared.in/rprogramming
Examples
> # example 2
> x <- 5
> y <- 2
> x ^ y
[1] 25
> x %% y
[1] 1
> x %/% y
[1] 2
r-squared
Slide 8
Column & Row Operations
www.r-squared.in/rprogramming
Operator Description
colSums Sum of column values
rowSums Sum of row values
colMeans Mean of column values
rowMeans Mean of row values
r-squared
Slide 9
Column & Row Operations
www.r-squared.in/rprogramming
Examples
> # example 1
> m
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
> colSums(m) # sum of columns
[1] 6 15 24
> rowSums(m) # sum of rows
[1] 12 15 18
> colMeans(m) # mean of columns
[1] 2 5 8
> rowMeans(m) # mean of rows
[1] 4 5 6
r-squared
Slide 10
Cumulative Operations
www.r-squared.in/rprogramming
Operator Description
cumsum Cumulative sums
cumprod Cumulative products
cummin Cumulative minima
cummax Cumulative maxima
r-squared
Slide 11
Cumulative Operations
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- 1:5
> cumsum(x)
[1] 1 3 6 10 15
> cumprod(x)
[1] 1 2 6 24 120
> x <- c(3:1, 2:0, 4:2)
> cummin(x)
[1] 3 2 1 1 1 0 0 0 0
> cummax(x)
[1] 3 3 3 3 3 3 4 4 4
r-squared
Slide 12
Miscellaneous Functions
www.r-squared.in/rprogramming
Operator Description
max Maxima
min Minima
pmax Parallel minima
pmin Parallel maxima
sum Sum of the values
prod Product of the values
range Min and Max of the values
r-squared
Slide 13
Miscellaneous Functions
www.r-squared.in/rprogramming
Examples
> # example 1
> x <- c(3, 26, 122, 6)
> min(x)
[1] 3
> max(x)
[1] 122
> prod(x)
[1] 57096
> sum(x)
[1] 157
> range(x)
[1] 3 122
r-squared
Slide 14
Miscellaneous Functions
www.r-squared.in/rprogramming
Examples
> # example 2
> x <- c(3, 26, 122, 6)
> y <- c(43,2,54,8)
> z <- c(9,32,1,9)
> pmin(x, y, z)
[1] 3 2 1 6
> pmax(x, y, z)
[1] 43 32 122 9
r-squared
Slide 15
sample()
www.r-squared.in/rprogramming
Description
sample() takes a sample of the specified size from the elements of an object, with or
without replacement.
Syntax
sample(x, size, replace = FALSE, prob = NULL)
Returns
Sample of the specified size.
Documentation
help(sample)
r-squared
Slide 16
sample()
www.r-squared.in/rprogramming
Examples
> example 1
> x <- 1:10
> sample(x)
[1] 10 1 4 2 9 7 5 6 8 3
> sample(10)
[1] 7 6 10 8 2 9 1 3 4 5
> sample(x, size = 5)
[1] 1 10 8 9 5
r-squared
Slide 17
sample()
www.r-squared.in/rprogramming
Examples
> example 2
> c <- c("Heads", "Tails")
> sample(c, size = 1)
[1] "Heads"
> sample(c, size = 2)
[1] "Tails" "Heads"
> sample(c, size = 10, replace = TRUE)
[1] "Tails" "Tails" "Tails" "Heads" "Heads" "Heads" "Tails" "Heads" "Heads" "Heads"
> table(sample(c, size = 10, replace = TRUE))
Heads Tails
5 5
r-squared
Slide 18
Set Operations
www.r-squared.in/rprogramming
Perform set operations on two vectors
Operation Description
union(x, y) Union of x and y
intersect(x, y) Intersect of x and y
setdiff(x, y) Elements in x and not in y
setequal(x, y) Test if x and y are equal
r-squared
Slide 19
Set Operations
www.r-squared.in/rprogramming
Examples
> example 1
> x <- 1:10
> y <- 6:15
> union(x, y)
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
> intersect(x, y)
[1] 6 7 8 9 10
> setdiff(x, y)
[1] 1 2 3 4 5
> setdiff(y, x)
[1] 11 12 13 14 15
> setequal(x, y)
[1] FALSE
r-squared
Slide 20
Logarithm
www.r-squared.in/rprogramming
Description
log() computes the natural logarithm.
Syntax
log(x, base)
Returns
Logarithm of the specified base or the natural logarithm
Documentation
help(log)
help(exp)
r-squared
Slide 21
log()
www.r-squared.in/rprogramming
Examples
> example 1
> log(10, base = 10)
[1] 1
> log(10, base = 2)
[1] 3.321928
> log(2.71828)
[1] 0.9999993
> # natural logarithm
> log(10)
[1] 2.302585
> # base 10
> log10(10)
[1] 1
r-squared
Slide 22
log()
www.r-squared.in/rprogramming
Examples
> # base 2
> log2(10)
[1] 3.321928
> # exponential
> exp(3)
[1] 20.08554
> 2.71828 ^ 3
[1] 20.0855
r-squared
In the next module, we will explore selection statements in R:
Slide 23
Next Steps...
www.r-squared.in/rprogramming
● if()
● if else()
● ifelse()
● switch()
r-squared
Slide 24
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

Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
Mohd Arif
 
Data preprocessing
Data preprocessingData preprocessing
Data preprocessing
ankur bhalla
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
Ankita Goyal
 

What's hot (20)

Data Types and Structures in R
Data Types and Structures in RData Types and Structures in R
Data Types and Structures in R
 
Dinive conquer algorithm
Dinive conquer algorithmDinive conquer algorithm
Dinive conquer algorithm
 
Data Mining: Outlier analysis
Data Mining: Outlier analysisData Mining: Outlier analysis
Data Mining: Outlier analysis
 
Introduction to R Programming
Introduction to R ProgrammingIntroduction to R Programming
Introduction to R Programming
 
Data preprocessing
Data preprocessingData preprocessing
Data preprocessing
 
3. R- list and data frame
3. R- list and data frame3. R- list and data frame
3. R- list and data frame
 
Random forest
Random forestRandom forest
Random forest
 
Classification and Regression
Classification and RegressionClassification and Regression
Classification and Regression
 
Naive bayes
Naive bayesNaive bayes
Naive bayes
 
Data mining primitives
Data mining primitivesData mining primitives
Data mining primitives
 
R programming
R programmingR programming
R programming
 
Bayes Belief Networks
Bayes Belief NetworksBayes Belief Networks
Bayes Belief Networks
 
Data Management in R
Data Management in RData Management in R
Data Management in R
 
Frequent itemset mining methods
Frequent itemset mining methodsFrequent itemset mining methods
Frequent itemset mining methods
 
Sets and disjoint sets union123
Sets and disjoint sets union123Sets and disjoint sets union123
Sets and disjoint sets union123
 
Data Exploration and Visualization with R
Data Exploration and Visualization with RData Exploration and Visualization with R
Data Exploration and Visualization with R
 
2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors2. R-basics, Vectors, Arrays, Matrices, Factors
2. R-basics, Vectors, Arrays, Matrices, Factors
 
Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.Lab report for Prolog program in artificial intelligence.
Lab report for Prolog program in artificial intelligence.
 
Feature selection
Feature selectionFeature selection
Feature selection
 
Daa
DaaDaa
Daa
 

Viewers also liked

Predictive Modeling using R
Predictive Modeling using RPredictive Modeling using R
Predictive Modeling using R
Rachit Jauhari
 
2.1 Energy Flow In Ecosystems
2.1 Energy Flow In Ecosystems2.1 Energy Flow In Ecosystems
2.1 Energy Flow In Ecosystems
schumaiers
 

Viewers also liked (8)

Predictive Modeling using R
Predictive Modeling using RPredictive Modeling using R
Predictive Modeling using R
 
meteodyn WT CFD modeling of forest canopy flows: input parameters, calibratio...
meteodyn WT CFD modeling of forest canopy flows: input parameters, calibratio...meteodyn WT CFD modeling of forest canopy flows: input parameters, calibratio...
meteodyn WT CFD modeling of forest canopy flows: input parameters, calibratio...
 
Multi-Scale Effects of Landscape Heterogeneity and Forest Management on Ungul...
Multi-Scale Effects of Landscape Heterogeneity and Forest Management on Ungul...Multi-Scale Effects of Landscape Heterogeneity and Forest Management on Ungul...
Multi-Scale Effects of Landscape Heterogeneity and Forest Management on Ungul...
 
DP Biology Topic 4.1 Species, Communities, & Ecosystems
DP Biology Topic 4.1 Species, Communities, & EcosystemsDP Biology Topic 4.1 Species, Communities, & Ecosystems
DP Biology Topic 4.1 Species, Communities, & Ecosystems
 
Actuarial Analytics in R
Actuarial Analytics in RActuarial Analytics in R
Actuarial Analytics in R
 
Class 8 mathematical modeling of interacting and non-interacting level systems
Class 8   mathematical modeling of interacting and non-interacting level systemsClass 8   mathematical modeling of interacting and non-interacting level systems
Class 8 mathematical modeling of interacting and non-interacting level systems
 
2.1 Energy Flow In Ecosystems
2.1 Energy Flow In Ecosystems2.1 Energy Flow In Ecosystems
2.1 Energy Flow In Ecosystems
 
LinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-PresentedLinkedIn SlideShare: Knowledge, Well-Presented
LinkedIn SlideShare: Knowledge, Well-Presented
 

Similar to R Programming: Mathematical Functions In R

ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
alexstorer
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
Rajib Layek
 
Practical Examples using Eviews.ppt
Practical Examples using Eviews.pptPractical Examples using Eviews.ppt
Practical Examples using Eviews.ppt
dipadtt
 

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

R Programming: Numeric Functions In R
R Programming: Numeric Functions In RR Programming: Numeric Functions In R
R Programming: Numeric Functions In R
 
R Programming: Comparing Objects In R
R Programming: Comparing Objects In RR Programming: Comparing Objects In R
R Programming: Comparing Objects In R
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
 
R/Finance 2009 Chicago
R/Finance 2009 ChicagoR/Finance 2009 Chicago
R/Finance 2009 Chicago
 
Oct.22nd.Presentation.Final
Oct.22nd.Presentation.FinalOct.22nd.Presentation.Final
Oct.22nd.Presentation.Final
 
R console
R consoleR console
R console
 
R Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In RR Programming: Transform/Reshape Data In R
R Programming: Transform/Reshape Data In R
 
R Programming: Export/Output Data In R
R Programming: Export/Output Data In RR Programming: Export/Output Data In R
R Programming: Export/Output Data In R
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
R Programming: Importing Data In R
R Programming: Importing Data In RR Programming: Importing Data In R
R Programming: Importing Data In R
 
ComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical SciencesComputeFest 2012: Intro To R for Physical Sciences
ComputeFest 2012: Intro To R for Physical Sciences
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Basic R
Basic RBasic R
Basic R
 
The SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and ComputationThe SAM Pattern: State Machines and Computation
The SAM Pattern: State Machines and Computation
 
Loops and functions in r
Loops and functions in rLoops and functions in r
Loops and functions in r
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
Practical Examples using Eviews.ppt
Practical Examples using Eviews.pptPractical Examples using Eviews.ppt
Practical Examples using Eviews.ppt
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptx
 
Grouping & Summarizing Data in R
Grouping & Summarizing Data in RGrouping & Summarizing Data in R
Grouping & Summarizing Data in R
 

More from Rsquared Academy

More from Rsquared Academy (20)

Handling Date & Time in R
Handling Date & Time in RHandling Date & Time in R
Handling Date & Time in R
 
Market Basket Analysis in R
Market Basket Analysis in RMarket Basket Analysis in R
Market Basket Analysis in R
 
Practical Introduction to Web scraping using R
Practical Introduction to Web scraping using RPractical Introduction to Web scraping using R
Practical Introduction to Web scraping using R
 
Joining Data with dplyr
Joining Data with dplyrJoining Data with dplyr
Joining Data with dplyr
 
Explore Data using dplyr
Explore Data using dplyrExplore Data using dplyr
Explore Data using dplyr
 
Data Wrangling with dplyr
Data Wrangling with dplyrData Wrangling with dplyr
Data Wrangling with dplyr
 
Writing Readable Code with Pipes
Writing Readable Code with PipesWriting Readable Code with Pipes
Writing Readable Code with Pipes
 
Introduction to tibbles
Introduction to tibblesIntroduction to tibbles
Introduction to tibbles
 
Read data from Excel spreadsheets into R
Read data from Excel spreadsheets into RRead data from Excel spreadsheets into R
Read data from Excel spreadsheets into R
 
Read/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into RRead/Import data from flat/delimited files into R
Read/Import data from flat/delimited files into R
 
Variables & Data Types in R
Variables & Data Types in RVariables & Data Types in R
Variables & Data Types in R
 
How to install & update R packages?
How to install & update R packages?How to install & update R packages?
How to install & update R packages?
 
How to get help in R?
How to get help in R?How to get help in R?
How to get help in R?
 
Introduction to R
Introduction to RIntroduction to R
Introduction to R
 
RMySQL Tutorial For Beginners
RMySQL Tutorial For BeginnersRMySQL Tutorial For Beginners
RMySQL Tutorial For Beginners
 
R Markdown Tutorial For Beginners
R Markdown Tutorial For BeginnersR Markdown Tutorial For Beginners
R Markdown Tutorial For Beginners
 
R Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar PlotsR Data Visualization Tutorial: Bar Plots
R Data Visualization Tutorial: Bar Plots
 
R Programming: Introduction to Matrices
R Programming: Introduction to MatricesR Programming: Introduction to Matrices
R Programming: Introduction to Matrices
 
R Programming: Introduction to Vectors
R Programming: Introduction to VectorsR Programming: Introduction to Vectors
R Programming: Introduction to Vectors
 
R Programming: Variables & Data Types
R Programming: Variables & Data TypesR Programming: Variables & Data Types
R Programming: Variables & Data Types
 

Recently uploaded

一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理
pyhepag
 
一比一原版纽卡斯尔大学毕业证成绩单如何办理
一比一原版纽卡斯尔大学毕业证成绩单如何办理一比一原版纽卡斯尔大学毕业证成绩单如何办理
一比一原版纽卡斯尔大学毕业证成绩单如何办理
cyebo
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
cyebo
 
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
pyhepag
 
Exploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptxExploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptx
DilipVasan
 
一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理
pyhepag
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
pyhepag
 

Recently uploaded (20)

MALL CUSTOMER SEGMENTATION USING K-MEANS CLUSTERING.pptx
MALL CUSTOMER SEGMENTATION USING K-MEANS CLUSTERING.pptxMALL CUSTOMER SEGMENTATION USING K-MEANS CLUSTERING.pptx
MALL CUSTOMER SEGMENTATION USING K-MEANS CLUSTERING.pptx
 
一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理一比一原版阿德莱德大学毕业证成绩单如何办理
一比一原版阿德莱德大学毕业证成绩单如何办理
 
一比一原版纽卡斯尔大学毕业证成绩单如何办理
一比一原版纽卡斯尔大学毕业证成绩单如何办理一比一原版纽卡斯尔大学毕业证成绩单如何办理
一比一原版纽卡斯尔大学毕业证成绩单如何办理
 
一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理一比一原版麦考瑞大学毕业证成绩单如何办理
一比一原版麦考瑞大学毕业证成绩单如何办理
 
2024 Q2 Orange County (CA) Tableau User Group Meeting
2024 Q2 Orange County (CA) Tableau User Group Meeting2024 Q2 Orange County (CA) Tableau User Group Meeting
2024 Q2 Orange County (CA) Tableau User Group Meeting
 
Artificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdfArtificial_General_Intelligence__storm_gen_article.pdf
Artificial_General_Intelligence__storm_gen_article.pdf
 
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
一比一原版(Monash毕业证书)莫纳什大学毕业证成绩单如何办理
 
Supply chain analytics to combat the effects of Ukraine-Russia-conflict
Supply chain analytics to combat the effects of Ukraine-Russia-conflictSupply chain analytics to combat the effects of Ukraine-Russia-conflict
Supply chain analytics to combat the effects of Ukraine-Russia-conflict
 
AI Imagen for data-storytelling Infographics.pdf
AI Imagen for data-storytelling Infographics.pdfAI Imagen for data-storytelling Infographics.pdf
AI Imagen for data-storytelling Infographics.pdf
 
Slip-and-fall Injuries: Top Workers' Comp Claims
Slip-and-fall Injuries: Top Workers' Comp ClaimsSlip-and-fall Injuries: Top Workers' Comp Claims
Slip-and-fall Injuries: Top Workers' Comp Claims
 
Exploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptxExploratory Data Analysis - Dilip S.pptx
Exploratory Data Analysis - Dilip S.pptx
 
一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理一比一原版西悉尼大学毕业证成绩单如何办理
一比一原版西悉尼大学毕业证成绩单如何办理
 
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
一比一原版加利福尼亚大学尔湾分校毕业证成绩单如何办理
 
Atlantic Grupa Case Study (Mintec Data AI)
Atlantic Grupa Case Study (Mintec Data AI)Atlantic Grupa Case Study (Mintec Data AI)
Atlantic Grupa Case Study (Mintec Data AI)
 
Easy and simple project file on mp online
Easy and simple project file on mp onlineEasy and simple project file on mp online
Easy and simple project file on mp online
 
How I opened a fake bank account and didn't go to prison
How I opened a fake bank account and didn't go to prisonHow I opened a fake bank account and didn't go to prison
How I opened a fake bank account and didn't go to prison
 
Machine Learning for Accident Severity Prediction
Machine Learning for Accident Severity PredictionMachine Learning for Accident Severity Prediction
Machine Learning for Accident Severity Prediction
 
Webinar One View, Multiple Systems No-Code Integration of Salesforce and ERPs
Webinar One View, Multiple Systems No-Code Integration of Salesforce and ERPsWebinar One View, Multiple Systems No-Code Integration of Salesforce and ERPs
Webinar One View, Multiple Systems No-Code Integration of Salesforce and ERPs
 
How can I successfully sell my pi coins in Philippines?
How can I successfully sell my pi coins in Philippines?How can I successfully sell my pi coins in Philippines?
How can I successfully sell my pi coins in Philippines?
 
2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call2024 Q1 Tableau User Group Leader Quarterly Call
2024 Q1 Tableau User Group Leader Quarterly Call
 

R Programming: Mathematical Functions In R