title: How To Repeat Same Select Function On Multiple Datasets In R Then Divide Them By The Number Of Rows
body: <p>So Basically I'm Trying To Find The % Of Items Containing A Certain Allergy In Food Products Then Divide It By The # Of Rows From That Specific Menu. Then Export it into a table.</p>
  
  <p>This Is The Code I'm Doing Right Now And It's Extremely Repetitive. </p>
  
  <pre><code>Gluten1.Contain &lt;- select(Arbys.Data, "Gluten") %&gt;%
  filter(Gluten == "YES") 
  
  rows1&lt;- nrow(Arbys.Data)
  
  Gx1 &lt;- c(count(Gluten1.Contain)/rows1)
  
  Arbys&lt;- as.character("Arbys")
  
  x1&lt;- c(Arbys,Gx1,Dx1,Ex1,Sx1,Px1,Tx1,Sfx1,Fx1,GDx1,GEx1,GSx1,GDEx1,
  GESx1,GDSx1,GDESx1, DEx1, DSx1, DESx1, ESx1)
  
  RP&lt;-rbind.data.frame(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,
  x14,x15,x16,x17, x18,x19,x20,x21,x22,x23,x24,x25,x26,x27,x28,x29,x30,
  x31,x32,x33,x34,x35,x36,x37,x38,x39,x40,x41,x42,x43,x44,x45,x46,x47,
  x48,x49,x50,x51,x52,x53,x54,x55,x56)
  
  names(RP) &lt; c("Restaurant","Gluten","Dairy","Egg","Soy","Peanut",
  "Treenut", "Shellfish","Fish","GD","GE","GS","GDE","GES","GDS","GDES",
  "DE", "DS","DES","ES")
  </code></pre>
  
  <p>The Letters Gx1 Dx1 etc stand for allergies and allergen combinations. d=dairy f=fish, etc.</p>
  
  <p>As You Can See I'm Doing This For 19 Different Combinations. and 56 restaurants. This is incredibly repetitive and time-consuming. How Can I make This simpler?</p>
  
  <p>Edit------------------------------------------------------------------</p>
  
  <p>So I Made A Function That Can Do All The Work. How Can I Apply This Function To A List Of CSV Files In A Folder And Make It Release As A Data Frame </p>
  
  <pre><code>Data.Fun&lt;- function(x) {
  
  { G &lt;- select(x, "Gluten") %&gt;%
  filter(Gluten == "YES") }
  
  
   {D &lt;- select(x, "Dairy") %&gt;%
    filter(Dairy == "YES") }
  
   {E &lt;- select(x, "Egg") %&gt;%
    filter(Egg == "YES") }
  
   {S &lt;- select(x, "Soybean") %&gt;%
    filter(Soybean == "YES") }
  
   {P &lt;- select(x, "Peanut") %&gt;%
    filter(Peanut == "YES") }
  
   {Tn &lt;- select(x, "Tree.Nuts") %&gt;%
    filter(Tree.Nuts == "YES") }
  
    {Sf &lt;- select(x, "Shellfish") %&gt;%
    filter(Shellfish == "YES") }
  
    {Fi &lt;- select(x, "Fish") %&gt;%
    filter(Fish == "YES") }
  
    {GDx &lt;- select(x, "Gluten", "Dairy") %&gt;%
  filter(Gluten == "YES", Dairy =="YES") }
  
    {GEx &lt;- select(x, "Gluten", "Egg") %&gt;%
  filter(Gluten == "YES", Egg =="YES") }
  
    {GSx &lt;- select(x, "Gluten", "Soybean") %&gt;%
  filter(Gluten == "YES", Soybean =="YES") }
  
    {GDEx &lt;- select(x, "Gluten", "Dairy", "Egg") %&gt;%
  filter(Gluten == "YES", Dairy =="YES", Egg =="YES") }
  
    {GDSx &lt;- select(x, "Gluten", "Dairy", "Soybean") %&gt;%
  filter(Gluten == "YES", Dairy =="YES", Soybean =="YES") }
  
    {GESx &lt;- select(x, "Gluten", "Soybean", "Egg") %&gt;%
  filter(Gluten == "YES", Soybean =="YES", Egg =="YES") }
  
    {GDESx &lt;- select(x, "Gluten", "Dairy", "Egg", "Soybean") %&gt;%
  filter(Gluten == "YES", Dairy =="YES", Egg == "YES", Soybean == "YES" ) }
  
    {DEx &lt;- select(x, "Egg", "Dairy") %&gt;%
  filter(Egg == "YES", Dairy =="YES") }
  
    {DSx &lt;- select(x, "Soybean", "Dairy") %&gt;%
  filter(Soybean == "YES", Dairy =="YES") }
  
    {DESx &lt;- select(x, "Egg", "Dairy", "Soybean") %&gt;%
  filter(Egg == "YES", Dairy =="YES", Soybean == "YES")} 
  
    {ESx &lt;- select(x, "Egg", "Soybean") %&gt;%
  filter(Egg == "YES", Soybean =="YES") }
  
  
  
  
  
  
    {Gluten &lt;- count(G)/nrow(x)}
    {Dairy &lt;- count(D)/nrow(x)}
    {Egg &lt;- count(E)/nrow(x)}
    {Soy &lt;- count(S)/nrow(x)}
    {Pnut &lt;- count(P)/nrow(x)}
    {Tnut &lt;- count (Tn)/nrow(x)}
    {ShellF &lt;-count (Sf)/nrow(x)}
    {Fish &lt;- count (Fi)/nrow(x)}
    {GD&lt;- count(GDx)/nrow(x)}
    {GE&lt;- count(GEx)/nrow(x)}
    {GS&lt;- count(GSx)/nrow(x)}
    {GDE&lt;- count(GDEx)/nrow(x)}
    {GDS &lt;- count(GDSx)/nrow(x)}
    {GES &lt;- count(GESx)/nrow(x)}
    {GDES &lt;- count(GDESx)/nrow(x)}
    {DE &lt;- count(DEx)/nrow(x)}
    {DS &lt;- count(DSx)/nrow(x)}
    {DES &lt;- count(DESx)/nrow(x)}
    {ES &lt;- count(ESx)/nrow(x)}
  
  
    {data.vector &lt;- c(Gluten, Dairy, Egg, Soy, Pnut, Tnut, ShellF, Fish, GD, GE, GS, GDE, GDS, GES, GDES, DE, DS, DES, ES)}
  
    {cbind.data.frame(data.vector)}
  
  }
  </code></pre>