In this post we will learn how to rename a column name in a dataframe with another name saved in a variable using dplyr. We will use dplyr’s rename() function in combination with special functions that are part of tidyverse’s tidy eval functionalities. First, let us load tidyverse and check the installed dplyr’s version. We… Continue reading How to Change Column Name with a variable name
Category: rstats101
dplyr case_when() to create new variable using multiple conditions
In this tutorial, we will learn how to use dplyr’s case_when() function to create a new variable based on multiple conditions. dplyr’s case_when() function offers a genereal solution when you might needed multiple if_else() conditions. In this blog post, we’ll explore case_when() function with multiple examples. Let us start with creating a simple data frame… Continue reading dplyr case_when() to create new variable using multiple conditions
How to Compute row means
In this tutorial, we will learn how to compute means of rows with tidyverse using dplyr package. We will see multiple examples to compute row means with dplyr. Wee will start with 3. examples of computing row means using rowMeans() and dplyr’s row-wise operations on a dataframe with no missing values. And then we will… Continue reading How to Compute row means
How to replace NAs with zero in a dataframe
In this post we will learn how to replace NAs, i.e. missing values with zeros in data frame in R. With tidyr’s replace_na() function, we can replace NAs in specific columns of a dataframe to zero or any other specific value. We will start with learning how to use replace_na() to replace NAs in a… Continue reading How to replace NAs with zero in a dataframe
How to compute inverse of a matrix in R
In this tutorial, we will show how to compute inverse of matrix in R. Computing inverse of a matrix is core to multiple applications. In linear algebra, inverse of a matrix is defined as a matrix that, when multiplied by the original matrix, results in the identity matrix. In other words, if A is a… Continue reading How to compute inverse of a matrix in R