title: Using a loop to create multiple data frames in R
body: <p>I have this function that returns a data frame of JSON data from the NBA stats website. The function takes in the game ID of a certain game and returns a data frame of the halftime box score for that game.</p>
  <pre><code>getstats&lt;- function(game=x){
    for(i in game){
      url&lt;- paste(&quot;http://stats.nba.com/stats/boxscoretraditionalv2?EndPeriod=10&amp;
                  EndRange=14400&amp;GameID=&quot;,i,&quot;&amp;RangeType=2&amp;Season=2015-16&amp;SeasonType=
                  Regular+Season&amp;StartPeriod=1&amp;StartRange=0000&quot;,sep = &quot;&quot;)
      json_data&lt;- fromJSON(paste(readLines(url), collapse=&quot;&quot;))
      df&lt;- data.frame(json_data$resultSets[1, &quot;rowSet&quot;])
      names(df)&lt;-unlist(json_data$resultSets[1,&quot;headers&quot;])
    }
    return(df)
  }
  </code></pre>
  <p>So what I would like to do with this function is take a vector of several game ID's and create a separate data frame for each one. For example:</p>
  <pre><code>gameids&lt;- as.character(c(0021500580:0021500593))
  </code></pre>
  <p>I would want to take the vector &quot;gameids&quot;, and create fourteen data frames. If anyone knew how I would go about doing this it would be greatly appreciated! Thanks!</p>