title: Join polygons by groups. What command should I use using dplyr with sf package
body: <p>I imported a shp file to R as an sf table and I would like to join my polygons with data.
  In just a 2 cases the data relates to an area of a city encompassing several polygons. For instance the data refers to the city with a 6 digits code ending with 1. But I have a map that just in the cases of two towns has town districts and codes ending with range from 2 to 6.</p>
  <p>I would like to join these polygons.
  First I replace id codes of the city distrct to represent only one code for a town in my data, ending with 1
  Then I imagine I should group by the code and join polygons by groups. How can I do that?</p>
  <pre><code>map_gminy &lt;- 
    map_gminy %&gt;% 
      mutate(
        gmina =
          if_else(str_detect(kod_teryt,&quot;10610&quot;),
                  &quot;Łódz&quot;,
                  gmina),
        kod_teryt =
          if_else(str_detect(kod_teryt,&quot;10610&quot;),
                  &quot;106101&quot;,
                  kod_teryt)
      ) %&gt;% 
        mutate(
        gmina =
          if_else(str_detect(kod_teryt,&quot;12610&quot;),
                  &quot;Kraków&quot;,
                  gmina),
        kod_teryt =
          if_else(str_detect(kod_teryt,&quot;12610&quot;),
                  &quot;126101&quot;,
                  kod_teryt)
        ) %&gt;% 
    group_by(kod_teryt) %&gt;% 
    sf_???????(gemometry)
  </code></pre>