title: Average Count of Columns with 2 groupby Condition in R
body: <p>I have a data table that consists of multiple variables based on the number of visits to each venue daily. I wanted to find the average visit count of each venue for Sat and Mon.</p>
  <p>I tried using the code but the output looks weird where the count for both days is the same. I do think that the output of the average count should be different based on the data I have.</p>
  <pre><code>new_data_selected &lt;- new_data %&gt;%
    select(c(&quot;venueType&quot;, &quot;buildingId&quot;, &quot;day&quot;, &quot;n&quot;)) %&gt;%
    filter (day == &quot;Mon&quot;| day == &quot;Sat&quot;) %&gt;%
    group_by(buildingId,day) %&gt;%
    summarise(Mean_visit = mean(n))
  </code></pre>
  <p>I created a random 25 rows of sample data to generate the dput.</p>
  <pre><code>dput(sample_data)
  
  structure(list(venueType = c(&quot;Restaurant&quot;, &quot;Pub&quot;, &quot;Pub&quot;, &quot;Restaurant&quot;, 
  &quot;Pub&quot;, &quot;Restaurant&quot;, &quot;Pub&quot;, &quot;Restaurant&quot;, &quot;Pub&quot;, &quot;Pub&quot;, &quot;Pub&quot;, 
  &quot;Pub&quot;, &quot;Restaurant&quot;, &quot;Pub&quot;, &quot;Restaurant&quot;, &quot;Restaurant&quot;, &quot;Pub&quot;, 
  &quot;Restaurant&quot;, &quot;Pub&quot;, &quot;Restaurant&quot;, &quot;Pub&quot;, &quot;Pub&quot;, &quot;Pub&quot;, &quot;Restaurant&quot;, 
  &quot;Restaurant&quot;), buildingId = c(&quot;86&quot;, &quot;238&quot;, &quot;585&quot;, &quot;164&quot;, &quot;502&quot;, 
  &quot;917&quot;, &quot;556&quot;, &quot;160&quot;, &quot;502&quot;, &quot;429&quot;, &quot;29&quot;, &quot;238&quot;, &quot;917&quot;, &quot;627&quot;, 
  &quot;27&quot;, &quot;181&quot;, &quot;238&quot;, &quot;101&quot;, &quot;164&quot;, &quot;101&quot;, &quot;502&quot;, &quot;953&quot;, &quot;29&quot;, 
  &quot;991&quot;, &quot;160&quot;), location = structure(list(structure(c(-820.92902794796, 
  4497.24330853014), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1702.53781555412, 
  3865.47709084848), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-225.920986645022, 
  3878.05369762611), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1623.07405914413, 
  3872.0300113645), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1524.95732116621, 
  3815.27149011437), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1771.45221663564, 
  4343.58017658314), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(964.43802317132, 
  3991.60347378421), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-3136.12789580931, 
  6671.91746186715), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1524.95732116621, 
  3815.27149011437), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-260.457470531391, 
  5026.15080417936), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(1809.88017335787, 
  4339.17242603545), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1702.53781555412, 
  3865.47709084848), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1771.45221663564, 
  4343.58017658314), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-3796.11985138919, 
  6367.92207258208), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-3529.55838697545, 
  4809.64112766693), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(1407.71076951492, 
  4010.45748152692), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1702.53781555412, 
  3865.47709084848), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-4131.41409222454, 
  7236.52563322564), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1608.76641144993, 
  3886.49247849546), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-4131.41409222454, 
  7236.52563322564), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1524.95732116621, 
  3815.27149011437), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-3209.73813918762, 
  6487.6576880651), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(1809.88017335787, 
  4339.17242603545), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-1176.80133020324, 
  5846.64712423648), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;)), structure(c(-3136.12789580931, 
  6671.91746186715), class = c(&quot;XY&quot;, &quot;POINT&quot;, &quot;sfg&quot;))), class = c(&quot;sfc_POINT&quot;, 
  &quot;sfc&quot;), precision = 0, bbox = structure(c(xmin = -4131.41409222454, 
  ymin = 3815.27149011437, xmax = 1809.88017335787, ymax = 7236.52563322564
  ), class = &quot;bbox&quot;), crs = structure(list(input = NA_character_, 
      wkt = NA_character_), class = &quot;crs&quot;), n_empty = 0L), daynum = c(17L, 
  11L, 9L, 3L, 19L, 8L, 27L, 22L, 31L, 15L, 2L, 27L, 18L, 22L, 
  16L, 1L, 10L, 22L, 5L, 31L, 17L, 13L, 4L, 6L, 10L), day = structure(c(5L, 
  4L, 7L, 3L, 7L, 5L, 6L, 6L, 3L, 6L, 4L, 5L, 1L, 3L, 2L, 3L, 3L, 
  3L, 6L, 3L, 1L, 2L, 1L, 5L, 6L), levels = c(&quot;Sun&quot;, &quot;Mon&quot;, &quot;Tue&quot;, 
  &quot;Wed&quot;, &quot;Thu&quot;, &quot;Fri&quot;, &quot;Sat&quot;), class = c(&quot;ordered&quot;, &quot;factor&quot;)), 
      n = c(982L, 741L, 1701L, 2020L, 835L, 423L, 622L, 1595L, 
      412L, 1703L, 742L, 532L, 413L, 998L, 216L, 1432L, 686L, 540L, 
      2104L, 258L, 729L, 1064L, 761L, 880L, 1609L)), class = c(&quot;grouped_df&quot;, 
  &quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;), row.names = c(NA, -25L), groups = structure(list(
      buildingId = c(&quot;101&quot;, &quot;101&quot;, &quot;160&quot;, &quot;160&quot;, &quot;164&quot;, &quot;164&quot;, 
      &quot;181&quot;, &quot;238&quot;, &quot;238&quot;, &quot;238&quot;, &quot;27&quot;, &quot;29&quot;, &quot;29&quot;, &quot;429&quot;, &quot;502&quot;, 
      &quot;502&quot;, &quot;502&quot;, &quot;556&quot;, &quot;585&quot;, &quot;627&quot;, &quot;86&quot;, &quot;917&quot;, &quot;917&quot;, &quot;953&quot;, 
      &quot;991&quot;), daynum = c(22L, 31L, 10L, 22L, 3L, 5L, 1L, 10L, 11L, 
      27L, 16L, 2L, 4L, 15L, 17L, 19L, 31L, 27L, 9L, 22L, 17L, 
      8L, 18L, 13L, 6L), .rows = structure(list(18L, 20L, 25L, 
          8L, 4L, 19L, 16L, 17L, 2L, 12L, 15L, 11L, 23L, 10L, 21L, 
          5L, 9L, 7L, 3L, 14L, 1L, 6L, 13L, 22L, 24L), ptype = integer(0), class = c(&quot;vctrs_list_of&quot;, 
      &quot;vctrs_vctr&quot;, &quot;list&quot;))), class = c(&quot;tbl_df&quot;, &quot;tbl&quot;, &quot;data.frame&quot;
  ), row.names = c(NA, -25L), .drop = TRUE))
  
  </code></pre>