as.numeric(): Converting to Numeric Values in R

R as.numeric() Method

The as.numeric() function in R converts valid non-numeric data into numeric data. What do I mean by valid non-numeric data? They are valid numeric values that are stored as text or categorical variables (factors). For example, “1” is a valid non-numeric data but “A” is not valid non-numeric data as far as the as.numeric() method … Read more

Dollar Sign ($ Operator) in R

Dollar operator ($) in R

In R, you can use the dollar sign ($ operator)  to access elements (columns) of a list or a data frame by their name. It also works with your environment. For example, it can fetch you the current environment variables. With its help, you can add, modify, or delete variables from the list and data … Read more

Calculating Absolute Value using abs() Function in R

R abs() Function

The abs() function calculates the absolute value of a numeric input, returning a non-negative (only positive) value by removing any sign. Usage of absolute value is high in fields like mathematical computations (mean absolute errors), statistical analysis, and data cleaning in ML tasks. Syntax abs(input) Parameters Argument Description input It defines the input object. It … Read more

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