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

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 columns into one column using three examples.… Continue reading 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 Let us create a data matrix using rnorm() function… Continue reading How to convert a matrix to a tidy table

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

How to Separate a Column into Multiple Rows in R: Hint tidyr’s spearate_row()

In this tutorial, we will learn how to separate a column with multiple elements separated by a delimiter into different rows. We will use tidy’s separate_rows() function first to separate a column with comma separated elements. And then show how to use separate_rows() on multiple columns. We will also see how to make separate_rows() function… Continue reading How to Separate a Column into Multiple Rows in R: Hint tidyr’s spearate_row()

Exit mobile version