R distinct() Function from dplyr

R dplyr distinct() Function

The dplyr::distinct() function in R removes duplicate rows from a data frame or tibble and keeps unique rows. You can provide additional arguments, like columns, to check for duplicates in those specific columns. Syntax distinct(.data, …, .keep_all = FALSE) Parameters Argument Description .data It is an input data frame or tibble from which to remove duplicate … 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

How to Remove NULL from List and Nested List in R

Removing NULL from List and Nested List in R

NULL represents a null object, and sometimes, it’s logical for the project to filter it out from either a list or data frame. Here are three ways to remove NULL values from a list in R: Using Filter() with Negate() and is.null() Using sapply() or lapply() with Subsetting Using purrr::discard() (Tidyverse Approach) For example, if … Read more

R basename() Function

R basename() Function

The basename() is a base R function that extracts the last component (or the ‘base name’) of a file or directory path and returns the name of the file or directory. So, if you have a path like “/Users/krunallathiya/Desktop/Code/pypro/data.pdf,“ basename() would return “data.pdf.“ The opposite function of basename() is dirname(), which gives the directory part of the path. Syntax basename(path) … Read more

How to Remove Duplicates from a Vector in R

Remove Duplicates from a Vector in R

In R, unique() and subsetting with !duplicated() are efficient ways to remove duplicates. Duplicate elements in a vector refer to those elements that appear more than once. Duplicates can skew the data analysis and lead to inaccurate results. Removing them leads to more reliable insights. Method 1: Using unique() The unique() function is a one-step, … Read more