A useful package for this may be dplyr. I’ll use a couple of bogus variables from the included iris dataset to give an indication of how this would work. In your case, replace iris with your dataset, and change the various calculations to what you need.
require(dplyr)
iris %>%
mutate(# Calculate required variables at the level of your raw data
Sepal.Area = Sepal.Length * Sepal.Width,
Petal.Area = Petal.Length * Petal.Width
) %>%
group_by(# Choose variable to group by
Species
) %>%
summarize(# Perform some grouping calculations
Mean.Sepal.Area = mean(Sepal.Area),
Mean.Petal.Area = mean(Petal.Area),
count = n()
) %>%
mutate(# Calculate required variables at the level of your summarized data
Sepal.Times.Petal = Mean.Sepal.Area * Mean.Petal.Area) ->
output
3
solved How do I break up a dataset in R so that particular values of a categorical variable are together, and I can then perform analysis of those values? [closed]