Aggregating Dataframe

I am creating a dataframe with data from runs of my program. I specify G, p, sep as my parameters, and then I have the prediction for G in my KL.Prediction column.
51%20PM
What I want to do is aggregate the predictions so I would have a table or dataframe or something showing that, for example, for G=4, p=2, sep=0.1, it predicted G=4, 4 times, and G=3, once. For G=4, p=3, sep=.1, it predicted G=4, 5 times, etc.

It would be easier to help you if you provide sample data on a copy/paste friendly format (a screenshot of your data is not very useful), check out this blog post by Mara that shows how to do it.

1 Like

Looks like you just want to group and count. Let me make this a reprex for you:


library(tidyverse)

n <- 500
df <- data.frame(
  G = sample(3:4, n, TRUE),
  p = sample(5:6, n, TRUE),
  sep = sample(c(.1, .2), n, TRUE),
  kl = sample(3:5, n, TRUE),
  div = sample(7:8, n, TRUE)
)

df %>% 
  group_by(G, p, sep, kl, div) %>%
  summarize(count = n())
#> # A tibble: 48 x 6
#> # Groups:   G, p, sep, kl [?]
#>        G     p   sep    kl   div count
#>    <int> <int> <dbl> <int> <int> <int>
#>  1     3     5   0.1     3     7     5
#>  2     3     5   0.1     3     8    11
#>  3     3     5   0.1     4     7    13
#>  4     3     5   0.1     4     8    11
#>  5     3     5   0.1     5     7     9
#>  6     3     5   0.1     5     8    11
#>  7     3     5   0.2     3     7    12
#>  8     3     5   0.2     3     8    13
#>  9     3     5   0.2     4     7    14
#> 10     3     5   0.2     4     8     9
#> # … with 38 more rows

Created on 2019-02-09 by the reprex package (v0.2.1)

So in the example above, G=3, p=5, sep=0.1, kl=3, and div=7 occurred 5 times.

Is this what you were after?

2 Likes

Thank you very much! It did exactly what I needed.

1 Like

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.