How to apply a function on multiple columns using across()

In this post, we will learn how to compute one or multiple functions on multiple columns using dplyr’s across() function. dplyr’s across() function can be used with summarize() or mutate() functions to operate on columns. In this example we will use summarize() function to compute mean values of multiple columns at the same time using… Continue reading How to apply a function on multiple columns using across()

dplyr across(): Compute column-wise mean

In this tutorial, we will learn how to use dplyr’s across() function to compute means of all columns in a dataframe. In R, we can use many approaches to compute column means. Here we will use tidyverse approach using dplyr’s across() function to compute column wise means. We will see two examples, first we will… Continue reading dplyr across(): Compute column-wise mean

How to Randomly Replace Values of Numerical Columns in a dataframe to NAs

In this tutorial, we will learn how to randomly replace values of numerical columns in a dataframe to NAs or missing values. We will use dplyr’s across() function to select only the numerical columns from a dataframe and probabilistically select certain percent of elements to change to NAs. First, let us load tidyverse packages and… Continue reading How to Randomly Replace Values of Numerical Columns in a dataframe to NAs

Exit mobile version