In this tutorial, we will learn how to rename column name of a dataframe in R using dplyr's rename() function. We will first see the basic syntax to use to change the name of a column with dplyr's rename(). Then we will see an example of of changing one column name and next wee … [Read more...] about dplyr rename(): How to rename column in r with dplyr
How to convert a matrix to a tidy table
In this tutorial, we will learn how to convert a data matrix to tidy long table. We will use tidyr's pivot_longer() function to reshape the matrix into a tidy table. First, let us start with loading the tidyverse suit of packages. Create a simulated data matrix … [Read more...] about How to convert a matrix to a tidy table
How to Convert Numerical Variable into a Categorical Variable in R
In this tutorial, we will learn how to convert numerical or continuous variable into categorical variable. We will start with the simple example converting a numerical variable into a categorical variable with just two levels. And then we will see an example of converting a … [Read more...] about How to Convert Numerical Variable into a Categorical Variable in R
How to sort columns alphabetically
In this tutorial, we will learn how to sort columns of a dataframe in alphabetical order. We will first use tidyverse to sort columns of a dataframe using two different ways. And then we will see how to use base R functions to sort the columns. Let us load … [Read more...] about How to sort columns alphabetically
dplyr if_else(): Create new variable from existing variable
With dplyr's if_else() function, we can create a new variable based on the values of another variable. if_else() function in dplyr takes in a condition as input and can assign a value based on the condition is true or false. In this example, we will use dplyr's if_else() to … [Read more...] about dplyr if_else(): Create new variable from existing variable