0% found this document useful (0 votes)
6 views

R Programming Built-In Function Notes

The document explains built-in functions in programming, categorizing them into numeric, statistical, and string functions. It provides examples for each type, detailing how to use functions like absolute, square root, mean, and string manipulation functions. These built-in functions simplify common programming tasks by allowing users to perform operations without needing to define them from scratch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

R Programming Built-In Function Notes

The document explains built-in functions in programming, categorizing them into numeric, statistical, and string functions. It provides examples for each type, detailing how to use functions like absolute, square root, mean, and string manipulation functions. These built-in functions simplify common programming tasks by allowing users to perform operations without needing to define them from scratch.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Builtin function

2)Builtin function: The functions which are already created or defined in the
programming framework are knows as built-in functions. User doesn’t need
to create these types of functions these functions are built into an
application. End-users can access these functions by simply calling it. Built in
functions are different types which are describe below

1)Numeric Function
2)Statistical Function
3)String Function
************************************************************
1)Numeric function: R provides the various mathematical functions to
perform the mathematical calculation.
a)Absolute function():It returns the absolute value of input x, Means this
function convert negative value to positive value.
EXAMPLE
x<- -6
print(abs(x))
b)Sqaure function; This functions returns the square root of input X.
EXAMPLE
x<-125
print(sqrt(x))
c)Round function(): This function is used to do the nearest integer value
round means if the decimal value is less then .5 (eg: 4.32 – it would not
returns round value). If the decimal value is more than .5(eg: 4.72 then it
would returns round value)
EXAMPLE:
x<-c(2.8,3.25,6.72,1.23)
print(round(x))
d)Celing function: It will round to the next integer value weather the decimal
is greather than 5 or less than 5. But this function works in positive condition
only, it cannot work in negative condition means it does not change negative
value.
EXAMPLE
x<-c(5.2, -5.2)
print(ceiling(x))

e)Floor function: It will round to the same integer value or down. Means it
work on negative values only.
Example
x<-c(5.2,-5.2,2.6)
print(floor(x))
f) Truncate Function: This function removes the fractional part of the number.
Mean it remove the number of decimal place but not rounding.
EXAMPLE
y<-c(1.5,5.67,8.9765)
print(trunc(y))

g) lox(x) log10 Function


EXAMPLE
x<-4
print(log(4))

base long
x<-4
print(log2(4))

x<-100
print(log10(100))

8)Exponential function(e^x): This function is used to calculate the power of e


or base.
EXAMPLE
i<-5
print(i^3)

2)Statistical Function: Statistical functions are a set of tool that allow to


perform various statistical calculation. There are some statistical function
which are describe below.
a) Mean function: This function is used to find the mean value.
Example1
a<-c(0:10,40)
xm<-mean(a)
print(xm)

EXAMPLE2
b<-c(2,6,7,8,9)
print(mean(b))
2)Standard deviation; This function returns standard deviation of an object.
EXAMPLE-1
a<-c(0:10,40)
xm<-sd(a)
print(xm)
EXAMPLE-2
a<-c(3,9,7,2)
print(sd(a))
3)Median(): This function returns the median value.
EXAMPLE-1
a<-c(1:15,30)
xm<-median(a)
print(xm)

4)Range(): It returns the value in range.


EXAMPLE:
a<-c(1:10,30)
xr<-range(a)
print(xr)
EXAMPLE-2
b<-c(2,16,17,9,12)
Print(range(b))

5)SUM(): This function is return sum.


EXAMPLE
a<-c(0:15,50)
print(sum(a))

6) Diff function: It returns difference with lag indicating which lag to use.
EXAMPLE
a<-c(0:10,40)
print(diff(a))

7)Min Function: It returns the minimum value.


EXAMPLE
b<-c(1:20,30)
print(min(b))
8)Max Function: It returns the minimum value.
EXAMPLE
b<-c(1:20,30)
print(max(b))

9)Scale function: Scale function is used to determine standardized value for


each element in a data set. It can be used to scale the values in a
vaector,matrix or dataframe.Basically scale is a technique for comparing data
that isn’t measured I the same way. The normalizing of a data set using the
mean value and standard deviation is know as scaling.
EXAMPLE
a<-matrix(1:9,3,3)
print(scale(a))

10)Factorial: Factorial is the operation of multiplying any natural number


with all the natural numbers that are smaller than it. This function is used to
find how many ways arrange or order a set number of things.
1!=1
2!=1*2
3!=1*2*3
4!=1*2*3*4

EXAMPLE
a<-c(1:10)
print(factorial(a))

3)String Function: A string is a sequence of character. There are some string


function which are describe below.
1)Substr Function: It is used to extract substrings in a character vector.
EXAMPLE
x<-"Builtinfunction"
print(substr(x,8,15))

2)tolower: This function is used to convert the string into lower case.
EXAMPLE
x<-"TOpOne"
print(tolower(x))

3)TOUPPER: This function is used to convert the string into Uppercase case.
EXAMPLE
Y<-"topone"
print(toupper(Y))
4)str_to_title: This function is used to convert the string into Prop case. For
this function first we need to install the package(stringr) and then use this
function for propcase.
install.packages("stringr")
library(stringr)
EXAMPLE
str<-"greeks for greeks"
print(str_to_title(str))

5)grep Function: Grep function is used to search the pattern of any vector.
EXAMPLE
S2<-c("abc","ade","adef","abcdefg")
pat<-"ade"
print(grep(pat,S2))
6)Sub function: Sub function is used to replace a particular vector or string
syntax=sub(pattern,replacement,x)
EXAMPLE
a1<-"SAS PROGRAMMING"
a1
a2<-sub("SAS","R",a1)
a2

7)paste Function: Paste function is used to concatenate the multiple strings. In


paste function the default separator is blank space.
EXAMPLE
y<-paste("Clinical",1,"R","Programming")
y
8)paste0: Paste0 is the faster than paste function. Paste0 remove all the space
present between the strings.
EXAMPLE
y<-paste0("Clinical",1,"R","Programming")
y

9)strsplit Function: This function is used to split the elements of character


vector.
EXAMPLE
a<-"split all the characte"
print(strsplit(a,""))
Note: If we give one space in between the quotation then the out will returns
in a separate words or strings.But If we not provide any space in between the
quotation then output returns in element wise.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy