In this tutorial, we will learn how to randomly select rows from a dataframe using dplyr's slice_sample() function in R. slice_sample() is the new way to randomly select rows either with replacement or without replacement and it supersedes an earlier function sample_n() in … [Read more...] about How to randomly select rows from a dataframe in R
dplyr row_number(): Add unique row number to a dataframe
In this tutorial, we will learn how to add unique row number to each row to a dataframe/tibble. We will use dply'r row_number() function to add unique row number as acolumn to a dataframe using tidyverse first. Then we will also see an example of adding a row number to a … [Read more...] about dplyr row_number(): Add unique row number to a dataframe
How to Replace NAs with Column mean using tidyverse
In this tutorial, we will learn how to replace missing values NAs in a data set with column means using tidyverse functions. Dealing with missing data is very important in doing data analysis. Understanding the origin of missing values NAs is very important to make a decision on … [Read more...] about How to Replace NAs with Column mean using tidyverse
How to Replace NA values with Column Mean
One of the ways to deal with missing values (or NAs) is to replace them with mean values (under certain assumptions). The process is called imputation. In this tutorial, we will learn how to replace missing values (NAs) with column mean. First we will create some data with … [Read more...] about How to Replace NA values with Column Mean
colSums in R – compute sum of all columns in a dataframe or matrix
In this tutorial, we will learn about colSums() function in base R and use it to calculate sum of all columns in a matrix or a dataframe. We will see two examples to understand the use colSums() function. First, we will calculate sum of all columns in a matrix and dataframe with … [Read more...] about colSums in R – compute sum of all columns in a dataframe or matrix