R bloggers

How to Aggregate Data in R

FavoriteLoadingAdd to favorites

The process involves two stages. First, collate individual cases of raw data together with a grouping variable. Second, perform which calculation you want on each group of cases. These two stages are wrapped into a single function. To perform aggregation, we need to specify three things in the code: The data that we want to aggregate The variable to group by within the data The calculation to apply to the groups (what you want to find out) Example data The raw data shown below consists of one row per case. Each case is an employee at a restaurant. Load the example data by running the following R code: library(flipAPI) data = DownloadXLSX(“https://wiki.q-researchsoftware.com/images/1/1b/Aggregation_data.xlsx”, want.row.names = FALSE, want.data.frame = TRUE) Perform aggregation with the following R code. agg = aggregate(data, by = list(data$Role), FUN = mean) This produces a table of the average…
Original Post: How to Aggregate Data in R