How to Check Data type of a Variable in R

Checking the data type of a variable in R

When it comes to checking the data type of a variable, it depends on what specific thing you are looking for in a variable, because you have many options to choose from. Each option tells you a different but important story. There are four main core functions to check data types in R: typeof(): It … Read more

Mastering grepl() Function in R

grepl() function in R

The grepl() function (stands for “grep logical”) in R searches for patterns within each element of a character vector. It returns a logical vector of the same length as input, where each value is either TRUE or FALSE. If the pattern matches that specific element, it returns TRUE. Otherwise, it returns FALSE. The above figure … Read more

How to Create Directory and File If It doesn’t Exist in R

Check and Create If a Directory and File Exists in R

When working with file systems, checking the directory or file existence is always better before commencing the operations. For a directory To create a directory, if it does not exist, use the dir.exists() function. After checking its existence, if it does not exist, you can use the dir.create() function to create a new directory with a specified … Read more

How to Create a Grouped Boxplot in R

R grouped boxplot with code example

To create a grouped boxplot in R, we can use the ggplot2 library’s aes() and geom_boxplot() functions. The aes() function maps the continuous and categorical variables to visual properties of a plot. The geom_boxplot() function creates a boxplot. There is a difference between a standard boxplot and a grouped boxplot. A standard boxplot provides a … Read more

R head() and tail() Functions

head() and tail() in R

For data exploration, quickly inspecting the data, verifying the structure, or debugging large datasets, we need some kind of tool that helps prevent excessive data flooding in the console. That’s where head() and tail() generic functions come into play. head() function The head() function displays the first n parts of the vector, matrix, table, or … Read more

Detailed Guide on %in% Operator in R

IN operator in R

The %in% operator checks if elements of one vector are present in another vector. It returns a logical vector of the same length as the left-side argument. Each element in the output is either TRUE or FALSE, depending on the value matching. If the value matches, it returns TRUE; otherwise, it returns FALSE. If you apply … Read more

NOT IN (%!in%) Operator in R

NOT IN operator in R

The %in% operator checks whether the element is present. And NOT IN (%!in%) operator does the exact opposite. The %!in% is a custom operator that checks if the elements of one vector are not present in another vector. It returns a logical vector of the same length as the left-hand vector, with TRUE for those … Read more

Calculating Mean, Median, and Mode in R

Calculating Mean, Mode, and Median in R

For understanding the central tendency of your input dataset, you need to calculate the basic summaries like mean, median, and mode. It gives you the data distribution, which tells you whether it is symmetrical or skewed. Mean Mean means the arithmetic average of a number in mathematics. An average is the sum of the total … Read more