Base functions are a set of functions in the R programming language that are included in the base package, which is automatically installed and loaded when the R problem executes. These functions provide a wide range of functionality, including mathematical operations, statistical functions, data manipulation, and input/output operations.
In this article, I will explain some R base functions from the R Programming Language.
R Mathematical Functions
R Base Package has a wide range of built-in mathematical functions that can be used to perform various types of mathematical operations, such as arithmetic, algebraic, trigonometric, and statistical functions.
The R Arithmetic operations are +
, -
, *
, /
, ^
, %/%
, %%
and below are some algebraic functions.
R Mathematical Functions | Description |
---|---|
abs() | Calculate the absolute value of a numeric vector. |
sqrt() | Calculate the square root of a numeric vector. |
round() | Calculate the round of a numeric vector. |
ceiling() | Round numbers up to the nearest integer. |
floor() | Round numeric values to the nearest integer. |
sign() | Returns -1 for negative values, Returns 1 for positive values, And 0 for zero. |
exp() | Calculate the exponential value of a numeric vector. |
log(), log10() | Calculate the natural logarithm of a numeric vector. |
These are just a few examples, and there are many more mathematical functions available in R. You can find a complete list of mathematical functions in the R documentation or by typing help(math)
in the R console.
R Statistical functions
R also has a wide range of built-in statistical functions that can be used to perform various types of statistical analyses, such as computing descriptive statistics, testing hypotheses, and fitting statistical models.
Besides R base functions, you can also use specialized packages in R, such as the stats
package, to access additional statistical functions.
Here are some examples of common statistical functions in R.
R Statistical functions | Description |
---|---|
mean() | |
median() | |
mode() | |
sd() | |
var() | |
quantile() | |
range() | |
max() | |
min() | |
sum() | |
prod() |
You can find a complete list of statistical functions in the R documentation or by typing help(stats)
in the R console.
R Input / Output Functions
R Input/Output Functions | Description |
---|---|
read.csv() | |
read.table() | |
write.csv() | |
write.table() | |
cat() | |
scan() | |
readLines() | |
paste() | |
format() | |
print(), sprintf(), print() | |
source() |
Data Manipulation
These data manipulation functions are pretty much used with Data Frames, Vectors, Lists, Matrices, and other R objects.
Base Functions | Description |
---|---|
with() | |
within() | |
head() | |
tail() | |
sort() | |
order() | |
unique() | |
duplicated() | |
which() | |
match() | |
table() | |
length() | |
nrow() | |
ncol() | |
attributes() | |
summary() | |
names() | |
is.na() | |
is.nan() | |
is.integer() | |
is.numeric() | |
is.complex() | |
is.character() | |
is.logical() | |
is.matrix() | |
is.array() | |
is.null() | |
is.data.frame() | |
is.vector() | |
is.list() | |
is.recursive() |
Conclusion
In this article, you have learned different R base package functions. Functions from the R base package are automatically installed and available to use by default. These functions provide a wide range of functionality, including mathematical operations, statistical functions, data manipulation, and input/output operation
Related Articles
- Select Rows based on Column Value in R
- Replace Values Based on Condition in R
- R Append Single or Multiple Rows to Data Frame
- Combine Two or Multiple Vectors in R
- R Combine Two or Multiple Lists
- R filter Data Frame by Multiple Conditions
- R Summarise on Group By in Dplyr
- R Group by Mean With Examples