How to Randomly Replace Values of Numerical Columns in a dataframe to NAs

In this tutorial, we will learn how to randomly replace values of numerical columns in a dataframe to NAs or missing values. We will use dplyr’s across() function to select only the numerical columns from a dataframe and probabilistically select certain percent of elements to change to NAs. First, let us load tidyverse packages and… Continue reading How to Randomly Replace Values of Numerical Columns in a dataframe to NAs

How to Randomly Replace Values in a Matrix to NAs

In this tutorial, we will see how to randomly replace values in a matrix to NAs, missing values. We will first create some data matrix by simulation. Here we create a matrix with 20 rows and 5 columns. The data matrix is complete without any missing values. To randomly introduce NAs, first we randomly select… Continue reading How to Randomly Replace Values in a Matrix to NAs

seq() function to create sequences

seq() function in R is one of the base R functions that is useful in creating sequences. In this tutorial, we will see multiple examples of creating sequence of numbers using seq() function. FIrst let us start with the simplest example of using seq() function. If you give a number as argument to seq() function,… Continue reading seq() function to create sequences

dplyr contains(): select columns that contains a string

In this tutorial, we will learn how to select columns, whose names contains a string using dplyr’s contains() function. dplyr’s contains() function belongs to a family helper functions to select columns like starts_with() and ends_with(). First we will see a simple example of using single string and selecting all columns that contains the string. And… Continue reading dplyr contains(): select columns that contains a string

dplyr transmute(): add new columns and delete existing columns

In this tutorial, we will learn how to create new columns and remove existing columns using dplyr’s transmute() function. We will start with an example showing how to use transmute to create one new column and then show an example of creating more than one new column. First, let us load tidyverse, the suite of… Continue reading dplyr transmute(): add new columns and delete existing columns

Exit mobile version