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 examples of using dplyr’s count() function with different arguments. First,… Continue reading dplyr count(): count unique values of a variable
Category: 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 dplyr. We will use storms dataset available with ggplot2 R package to… Continue reading 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 dataframe using base R… Continue reading 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 to machine… Continue reading dplyr near(): compare if numbers and vectors are nearly the same