R Built-In Functions R Numeric Functions: Abs (X)
R Built-In Functions R Numeric Functions: Abs (X)
R Numeric Functions
1) abs(x) :- It returns the absolute value of input x.
x<- -4
print(abs(x))
2) sqrt(x):- It returns the square root of input x.
print(sqrt(x))
3) exp(x) : It returns exponent.
print(exp(x))
String Function
1) substr(x, start=n1,stop=n2)
It is used to extract substrings in a character vector.
a <- "987654321"
substr(a, 3, 3)
O/P
2) grep(pattern, x , ignore.case=FALSE, fixed=FALSE)
It searches for pattern in x.
st1 <- c('abcd','bdcd','abcdabcd')
pattern<- '^abc'
print(grep(pattern, st1))
O/P
3) sub(pattern, replacement, x, ignore.case =FALSE, fixed=FALSE)
It finds pattern in x and replaces it with replacement (new) text.
st1<- "England is beautiful but no the part of EU"
sub("England', "UK", st1)
O/P:
4) strsplit(x, split)
It splits the elements of character vector x at split point.
a<-"Split all the character"
print(strsplit(a, ""))
O/P:
5) tolower(x)
It is used to convert the string into lower case.
st1<- "SneHa"
print(tolower(st1))
O/P:
6) toupper(x)
It is used to convert the string into upper case.
st1<- "SneHa"
print(toupper(st1))
O/P:
i) User-defined functions
1) Strings in Vector
x <- c("Geeks", "Hello", "Welcome", "For")
2) Strings in Matrix
blank_matrix = generate_adj_matrix(string_in)
3) Strings in Arrays
5) Strings in lists
myList <- list(1:5, "MSSQLTips", c(TRUE, FALSE, TRUE), c(3.3, 9.9, 12.2))
str(myList)