## What is the cos() Function in R

The cos() function in R is “used to calculate the cosine of a number in radians”. Syntax cos(x) Parameters x: The cos() function takes x as a numeric or complex vector argument. To convert degrees to radians, use the following formula. radians = degrees * ( pi / 180.0 ) Example 1: Simple use of the … Read more

## What is the kable() Function in R

The kable() function in R is a part of the knitr package “used to generate a table against the provided value”. Syntax kable(data) Parameters data: It is an R object or data frame.  Return Value The kable() function returns a table for a data object. If the input is a list of objects, it returns … Read more

## What is the min() Function in R

The min() function in R is “used to return the minimum value of a vector or data frame”. Syntax min(input, na.rm = FALSE) Parameters input: It is a  vector or a data frame. na.rm: It removes the NA values; if it mentions FALSE, it considers NA, or if it mentions TRUE, it removes NA from … Read more

## Usage of %in% Operator in R

The %in% operator in R is “used to check if the values of the first argument are present in the second argument and return a logical vector indicating if there is a match”. Example 1: Usage of the %in% operator v1 <- 4 v2 <- 11 t <- 1:10 print(v1 %in% t) print(v2 %in% t) Output … Read more

## R switch() Function (With Examples)

The switch() function in R “tests an expression against the elements of a list, and if the value evaluated from the expression matches the element from the list, the corresponding value is returned“. Syntax switch (expression, val1, val2) Parameters expression: It is a parameter evaluated, and based on this value, the corresponding item in the … Read more

## How to Convert Matrix to List in R

Here are two ways to convert a matrix to a list in R: Method 1: Using the as.list() along with unlist() function To convert a matrix to a list, the easiest way is to use the “as.list()” along with the “unlist()” function. Example 1: Convert a matrix to a list of lists in column-major order … Read more

## How to Use the map() Function in R

The map() function from the purrr package in R “is used to apply a function to each element in a vector or list and return a list as a result”. Syntax map(rv, func, …) Parameters rv: It is an atomic vector or list. func: It is a function, formula, or atomic vector. If it is … Read more

## unlink in R: How to Delete Files or Directories in R

The unlink() function in R is “used to delete the file(s) or directories”. Syntax unlink(x, recursive = FALSE, force = FALSE) Parameters x: It is a character vector with the file(s) names or directories to be deleted. Wildcards (normally * and ?) are allowed. recursive: It is a logical argument. If recursive = FALSE, directories … Read more

## What is the month.abb in R

The “month.abb” is a built-in R constant, a “three-letter abbreviation” for the English month names. Example month.abb Output  “Jan” “Feb” “Mar” “Apr” “May” “Jun” “Jul” “Aug” “Sep” “Oct” “Nov” “Dec” Changing abbreviations to numerical month values If you have a vector of integers consisting of the number of the month, then you can use … Read more

## How to Calculate a Median in R (6 Examples)

The median in R is the “middle value of a data set”. It is calculated by sorting the data set from least to greatest and then finding the value in the middle. If the data set has an even number of values, the median is the average of the two middle values. To calculate a … Read more