New to R and need help with groupby & summarise

I have a dataset that has various user Ids in a column with rows with information. I need a code that allows me to combine users with the same Id so that I can summarize their information. Thanks in advance for your help.

Hi there,

Here is an example below of how to accomplish something like that with this dummy dataset. As you can see here we group the different species and count that number of observations while also working out their mean sepal lengths. You can do something smiliar for your data.

library(tidyverse)

iris %>% 
  group_by(Species) %>% 
  summarise(count_species = n(), average_sepal_length = mean(Sepal.Length))
#> # A tibble: 3 x 3
#>   Species    count_species average_sepal_length
#>   <fct>              <int>                <dbl>
#> 1 setosa                50                 5.01
#> 2 versicolor            50                 5.94
#> 3 virginica             50                 6.59

Created on 2021-10-22 by the reprex package (v2.0.0)

1 Like

Thank you GM, it worked! Is there a cheat sheet where I can find code in one place with math codes for analysis?

The functions used above is part of dplyr. You can have a look here at its cheatsheet: https://raw.githubusercontent.com/rstudio/cheatsheets/master/data-transformation.pdf

Others are available here: RStudio Cheatsheets - RStudio and here: https://github.com/rstudio/cheatsheets

1 Like

:pray:t5: :+1:t5: :pray:t5: This is super helpful! Thanks for taking the time!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.