You probably want to use the combination of group_by()
and mutate()
. This will compute the summary score (max value, for example) but not collapse the data.
For example:
library(dplyr)
iris %>%
group_by(Species) %>%
mutate(max_score = max(Sepal.Length)) %>%
ungroup()
#> # A tibble: 150 x 6
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species max_score
#> <dbl> <dbl> <dbl> <dbl> <fct> <dbl>
#> 1 5.1 3.5 1.4 0.2 setosa 5.8
#> 2 4.9 3 1.4 0.2 setosa 5.8
#> 3 4.7 3.2 1.3 0.2 setosa 5.8
#> 4 4.6 3.1 1.5 0.2 setosa 5.8
#> 5 5 3.6 1.4 0.2 setosa 5.8
#> 6 5.4 3.9 1.7 0.4 setosa 5.8
#> 7 4.6 3.4 1.4 0.3 setosa 5.8
#> 8 5 3.4 1.5 0.2 setosa 5.8
#> 9 4.4 2.9 1.4 0.2 setosa 5.8
#> 10 4.9 3.1 1.5 0.1 setosa 5.8
#> # … with 140 more rows
Created on 2020-02-11 by the reprex package (v0.3.0)