title: What's the easiest way to duplicate observations in a dataset while making a small change to each new observation?
body: <p>first-time poster, so I hope I'm giving enough information, and I hope that this question isn't an obvious duplicate (I ran a search and couldn't find exactly what I needed). If I can clarify anything, please let me know!</p>
  <p>I'm an R novice working on a group project using NBA play-by-play data, and my group is looking at the effect of the shot clock on certain possession outcomes. Right now, we have dummy variables for every second elapsed on the shot clock in each row. For example, a possession that lasted 10 seconds would have a value of 1 for the dummies 24, 23, 22, 21, 20, 19, 18, 17, 16, and 15 and a zero for the remaining dummies 14-1.</p>
  <p>Here's a simplified sample of what the current dataset would look like:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>PossessionID</th>
  <th>OffensiveTeam</th>
  <th>DefensiveTeam</th>
  <th>Points</th>
  <th>24</th>
  <th>23</th>
  <th>22</th>
  <th>21</th>
  <th>20</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>12345</td>
  <td>CHI</td>
  <td>IND</td>
  <td>2</td>
  <td>1</td>
  <td>1</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12346</td>
  <td>IND</td>
  <td>CHI</td>
  <td>0</td>
  <td>1</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12347</td>
  <td>CHI</td>
  <td>IND</td>
  <td>3</td>
  <td>1</td>
  <td>1</td>
  <td>1</td>
  <td>1</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>And here's what we need it to look like for those same 3 entries from above:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>PossessionID</th>
  <th>OffensiveTeam</th>
  <th>DefensiveTeam</th>
  <th>Points</th>
  <th>24</th>
  <th>23</th>
  <th>22</th>
  <th>21</th>
  <th>20</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>12345</td>
  <td>CHI</td>
  <td>IND</td>
  <td>2</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12345</td>
  <td>CHI</td>
  <td>IND</td>
  <td>2</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12345</td>
  <td>CHI</td>
  <td>IND</td>
  <td>2</td>
  <td>0</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12346</td>
  <td>IND</td>
  <td>CHI</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12346</td>
  <td>IND</td>
  <td>CHI</td>
  <td>0</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12347</td>
  <td>CHI</td>
  <td>IND</td>
  <td>3</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12347</td>
  <td>CHI</td>
  <td>IND</td>
  <td>3</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12347</td>
  <td>CHI</td>
  <td>IND</td>
  <td>3</td>
  <td>0</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12347</td>
  <td>CHI</td>
  <td>IND</td>
  <td>3</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>1</td>
  <td>0</td>
  </tr>
  <tr>
  <td>12347</td>
  <td>CHI</td>
  <td>IND</td>
  <td>3</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>0</td>
  <td>1</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>In case the difference isn't clear, we need to create rows such that each row has only one of the dummies equal 1 and hold the rest of the values in the row constant. Note how the 1s &quot;cascade&quot; down with each new row, but the rest of the values are the same for each row from the original dataset.</p>
  <p>Does anyone have a suggestion for how best to create these new rows? Ideally would be one that uses nothing beyond base R, tidyverse, and dplyr. Thanks so much!</p>