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

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

R type.convert() Function: Complete Guide

R type.convert() Function

The type.convert() is a built-in R function that intelligently converts a vector, factor, or data frame column into the most appropriate data type (integer, numeric, logical, complex, or factor) based on its content. Please note that we don’t need to specify which data type to convert to; this function automatically determines, which is the main … Read more

How to Create an Empty Vector and Append Values in R

Creating an Empty Vector and Append Values in R

R vectors are atomic, which means they have homogeneous data types. They are contiguous in the memory. Here are some of the best approaches for vector initialization and appending values in the future: Using type-specific functions The most efficient and quickest way to create an empty vector is to use type-specific functions like numeric(0), which … Read more

R append() Function: Complete Guide

append() function in R

The append() function in R concatenates values to a vector or list at a specified position. It returns a new object without modifying the original. You can add a single or multiple elements to a vector or list. Syntax append(obj, values, after = length(x)) Parameters Name Value obj It is an original vector or list. … Read more