How to collapse multiple rows based on a column

In this tutorial, we will learn how to collapse multiple rows from a column to a single row based on another column/group. Let us get started by loading tidyverse and checking the tidyr package version. To illustrate collapsing multiple rows into single one, let us create a toy dataframe with continents and countries. Our aim… Continue reading How to collapse multiple rows based on a column

How to select columns that starts with a prefix/string in R

In this tutorial, we will learn how to select columns that starts with a prefix or string using dplyr’s strats_with() function and base R startsWith() function. The tidyverse R package dplyr has a number of helper functions to select columns of interest under different condition. dplyr’s starts_with() function is one of select helper functions to… Continue reading How to select columns that starts with a prefix/string in R

Linear Regression in R with lm() function – A Practical Tutorial

Scatterplot with linear fit line

In this tutorial, we will learn how to perform a simple linear regression in R using lm() function. Simple Linear regression is one of the popular and common statistical methods that is used to understand the relationship between two numerical or quantitative variables, like height and weight of humans, age and height, years of education… Continue reading Linear Regression in R with lm() function – A Practical Tutorial

How To find levels of a factor in R

Factors are a type of variable that R uses to store categorical information in R. For example, we can save sexes as factor variable with two values male and female. In this post we will learn about using factor variables in R and learn how to find out about levels of a factor variable in… Continue reading How To find levels of a factor in R

How to Split a Dataframe into a list of Dataframes by groups in R

In this tutorial, we will learn how to split a dataframe into a list of dataframes by groups in R. We will first learn how to use the base R function, split(), to divide a dataframe into multiple dataframes into a list. Then, we will learn how to use dplyr’s group_split() function to do the… Continue reading How to Split a Dataframe into a list of Dataframes by groups in R

Exit mobile version