In this tutorial, we will learn how to count unique values of a variable(s) or column using dplyr's count() function. dplyr's count() function is a convenient function that combines grouping operation and counting the number of observation in each group. We will learn of 4 … [Read more...] about dplyr count(): count unique values of a variable
dplyr
How to randomly select rows from a dataframe in R
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
dplyr near(): compare if numbers and vectors are nearly the same
In this tutorial, we will learn near() function part of R package dplyr to check the equality of two numbers or vectors. Often we would like to compare if two numbers or two vectors are equal. A naive approach of using == to compare if two numbers are equal can be problematic due … [Read more...] about dplyr near(): compare if numbers and vectors are nearly the same