Working on Cases

This section focuses on functions that help create, add, modify or transform cases/observations.

Credits: icons adapted from Rstudio cheat sheet Data Transformation with dplyr : : CHEAT SHEET – CC BY SA RStudio


The function summarize() (which may also be written summarise()) creates a table in which you will find the result(s) of the summary function(s) you have chosen to apply to a data frame. The summary functions may be: mean(): which returns the mean of a variable, sd(): which returns the standard […]

Summarize Cases


group_by() is a function that groups the cases (rows) of the table according to the different factors of a chosen categorical variable. When used alone, it transforms a data frame into a new table where the factors of the chosen variable are registered as grouped. The output table is then […]

Group Cases


Count() does exactly what it says: it counts the number of cases! Applied directly to a data frame, count() will provide you with the number n of cases. Applied to a table which has been pre-grouped with group_by() (read more about group_by() here) or in a pipe in combination with […]

Count Cases



dplyr has a handful of functions that allow for cleaning a data set by selecting a specific subset of observations. Here are the functions we will look at here: filter(): extract rows that meet logical criteria slice(): extract rows by position top_n: extract the rows containing the n highest/lowest values […]

Extract Cases


The dplyr function arrange() allows for reordering data frames and tables based on the content of one or more variables. The function is quite simple and sorts all variables in ascending order by default. Here is an example where the variable age is sorted: Orange %>% arrange(age)   To sort […]

Arrange Cases


The dplyr function add_case() allows for adding cases to an existing data set, whether at the end of the set or a predefined place of the table. Note that there exist a function called add_row() which does exactly the same as add_case(). The syntax is simple. Between the parentheses of […]

Make New Cases



There are often situations where you need to update a data frame with additional cases, to merge different chronological versions of a data frame, to find out whether you have similar entries in two data frames,… in other words, situations where you need to identify and compare rows in two […]

Import Cases