In this tutorial, we will learn how to create all possible combinations of two variables using tidyr's expand_grid() function. For example, if we have two variables of interest and want to create a dataframe with all possible combinations of the values of the two variables, we … [Read more...] about expand_grid(): Create all possible combinations of variables
tidyr
tidyr’s separate_delim_wider(): Split a string into columns
In this tutorial, we will learn how to split a string in a column into multiple columns using a delimiter. We will use tidyr's separate_delim_wider() function, that separates a string in a column into multiple columns using delimiter. After spliting the dataframe is wider with … [Read more...] about tidyr’s separate_delim_wider(): Split a string into columns
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() … [Read more...] about How to replace NAs with zero in a dataframe
tidyr unite(): combine multiple columns into one
In this tutorial, we will learn how to use unite() function in tidyr package to combine multiple columns into a single column. By combining , we mean to concatenate the values of two or more columns separated by a delimiter like underscore. We will start with combining two … [Read more...] about tidyr unite(): combine multiple columns into one
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