How to Convert Date to Numeric in R

Converting Date to Numeric Value in R

Dates in R are stored as the number of days since 1970-01-01, so converting a Date object to a Numeric gives those day counts. But what about POSIXct? Well, those are stored as seconds since the same epoch, so converting them would give a much larger number. Here are three ways to convert Date to … 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 Transpose Data Frame in R

Transposing Data Frame in R

Transposing means switching rows to columns and columns to rows. It is a common operation in the matrix.  The above figure shows that column names from the original data frame have become row names, and the first column values of the original data frame have become column names. Everything has been switched. Here are two … Read more