Hi, I am very new to R studio and I am struggling with the following problem:
I have the following dataset:
Code Value
6300001 0.51
6300001 0.89
6300001 10.05
6300001 10.05
6300001 10.05
6300001 10.25
6300014 0.31
6300014 1.13
6300014 1.64
6300046 901.54
6300046 95.49
6300049 1.34
6300049 10.33
Now, I need to summarize each code with a minimum, maximum and mean 'Value'. How do I link all these same 'Code' values and then summarize them all?
Thanks in advance!
It seems that you are already aware of the group_by() and summarise() functions from the dplyr package. An excellent resource to learn R in general and the tidyverse in particular is R for Data Science by Hadley Wickham. It is online at
https://r4ds.had.co.nz/
Look at section 5.6 Grouped summaries with summarise()
1 Like
values <- tibble::tribble(
~Code, ~Value,
6300001, 0.51,
6300001, 0.89,
6300001, 10.05,
6300001, 10.05,
6300001, 10.05,
6300001, 10.25,
6300014, 0.31,
6300014, 1.13,
6300014, 1.64,
6300046, 901.54,
6300046, 95.49,
6300049, 1.34,
6300049, 10.33
)
values %>%
group_by(Code) %>%
summarise(min = min(Value),
max = max(Value),
mean = mean(Value))
system
Closed
October 20, 2021, 11:30am
4
This topic was automatically closed 21 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.