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
tidyverse all_of(): select columns from a vector
In this tutorial, we will learn about how to select multiple columns from a dataframe by using the column names as a vector at once. tidyverse' tidyselect package has numerous options for selecting columns from a datafame. all_of() is one of the functions in tidyselect that … [Read more...] about tidyverse all_of(): select columns from a vector
pivot_longer on dataframe with single row
In this tutorial, we will see an example of using pivot_longer() function to reshape, a dataframe with a single row, from wide form to long tidy form. Sometimes you might have a dataframe with just one long row and it is useful to reshape into longer format. We will start … [Read more...] about pivot_longer on dataframe with single row