title: Delete row from data.frame based on condition
body: <p>I have some repeated measures data I'm trying to clean in <code>R</code>. At this point, it is in the long format and I'm trying to fix some entries before I move to a wide format - for example, if people took my survey too many times I'm going to drop the rows. I have two main problems that I'm trying to solve:</p>
  <h1>Changing an entry</h1>
  <p>If someone took the survey from the &quot;pre-test link&quot; when it was actually supposed to be a post-test, I'm fixing it with the following code:</p>
  <pre><code>data[data$UserID == 52118254, &quot;Prepost&quot;][2] &lt;- 2
  </code></pre>
  <p>This filters out the entries from that person based on ID, then changes the second entry to be coded as a post-test. This code has enough meaning that reviewing it tells me what is happening.</p>
  <h1>Dropping a row</h1>
  <p>I'm struggling to get meaningful code to delete extra rows - for example if someone accidentally clicked on my link twice. I have data like the following:</p>
  <pre><code>    UserID Prepost Duration..in.seconds.
  1 52118250       1                   357
  2 52118284       1                   226
  3 52118284       1                    11 #This is an extra attempt to remove
  4 52118250       2                   261
  5 52118284       2                   151
  #to reproduce:
  structure(list(UserID = c(52118250, 52118284, 52118284, 52118250, 52118284), Prepost = c(&quot;1&quot;, &quot;1&quot;, &quot;1&quot;, &quot;2&quot;, &quot;2&quot;), Duration..in.seconds. = c(&quot;357&quot;, &quot;226&quot;, &quot;11&quot;, &quot;261&quot;, &quot;151&quot;)), class = &quot;data.frame&quot;, row.names = c(NA, -5L), .Names = c(&quot;UserID&quot;, &quot;Prepost&quot;, &quot;Duration..in.seconds.&quot;))
  </code></pre>
  <p>I can filter by UserID to see who has taken it too many times and I'm looking for a way to easily remove those rows from the dataset. In this case, UserID 52118284 has taken it three times and the second attempt needs to be removed. If it is &quot;readable&quot; like the other fix that is better.</p>