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 numerical variable into a categorical variable with multiple levels. Let… Continue reading How to Convert Numerical Variable into a Categorical Variable in R

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 categorise or dichotomise a numerical variable… Continue reading 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 helps us selecting multiple columns using a character vector.… Continue reading 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 with creating a dataframe with… Continue reading pivot_longer on dataframe with single row

Exit mobile version