R_WEEK7: Functions

PinnacleVex KA Analytics
2 min readJun 20, 2021

We know that there are many R functions organized in different packages, but we need to familiar with those functions like how and where to use. When we have a particular requirement then it’s better to write our own function and implement it.
i’m listing some of the built in functions we are familiar with, toupper(), substr(), paste(), summary(), mean(), hist(), rnorm(), abs(), sqrt(), ceiling(), floor(), trunc(), log() etc…

Functions in R are created using the function() directive and they are stored as objects i.e. they are R objects of class “function” means .
fun <- function(<arguments>) {
# Write your requirements
}

1. Simple function without any arguments
hello_pinn <- function(){
print(‘Hello pinnaclevex’)
}

Hello_pinn()

2. Simple function with a single argument
name_fun <- function(name){
print(paste(‘Hello pinnaclevex ‘, name))
}

name_fun(‘KA Analytics’)

3. Simple function with two argument
mult_fun <- function(ar1, ar2){
print(ar1*ar2)
}

mult_fun(3, 9)

4. Function with default argument values

hey_p <- function(name=’pinnaclevex’) {
print(paste(‘Hey’, name))
}

hello_p()
hello_p(‘KA’)
hello_p(name=’Analytics’)

5. Returning the value from a Function with Return
full_nam <- function(name1=’pinnaclevex’, name2=’KA Analytics’) {
return(paste(name1,’ ‘, name2))
}
full_nam()
full_nam(‘KA’)
full_nam(name=’Analytics’)

Happy Learning !!! :)

Related Articles:

R in Clinical World: WEEK6 Solution

R in Clinical World: WEEK6 Task

R in Clinical World: WEEK5

R in Clinical World: WEEK4

R in Clinical World: WEEK3

R in Clinical World: WEEK2

R in Clinical World: WEEK1

Introduction to POWER BI

PinnacleVex KA Analytics: BASICS OF MICROSOFT EXCEL

PinnacleVex KA Analytics: Basic Excel Formulas For Your Daily Workflow

PinnacleVex KA Analytics: Simple introduction to SQL

PinnacleVex KA Analytics: Clinical Trials

PinnacleVex KA Analytics Clinical Data Management

My_website

LinkedIn

Youtube

Facebook

Twitter

Instagram

Youtube

--

--

PinnacleVex KA Analytics

PinnacleVex KA Analytics is a Healthcare and IT Service Provider Headquartered at Hyderabad, India.