title: R: How to get rid of rows depending on a calculation applied in a certain column, that refers to values of other columns?
body: <p>I have a df with the columns subject(subj), condition, reaction time(rt_link). Each row is one trial. I calculated the means and SDs of RTs per subject and Condition:</p>
  <pre><code>RTs_overview &lt;- links_RTs %&gt;% 
    group_by(subj, condition) %&gt;% 
    summarize(mean_rt = mean(rt_link),
              sd_rt = sd(rt_link))
  </code></pre>
  <p>and it gives out a nice df showing the subject, the condition and mean and SD of RTs each, so there are 4 rows per subject, one for each condition.
  I would now like to get rid of all rows where the RT is &gt; or &lt; 3SDs of the mean of the corresponding subject and condition. Earlier, I got rid of rows with RTs &gt; 10s, with this:</p>
  <pre><code>links_RTs &lt;- links_cl[links_cl$rt_link &lt; 10, ]
  </code></pre>
  <p>I tried to do the same now, but unsuccessfully</p>
  <pre><code>links_RTs[links_RTs$rt_link &lt; (lapply(mean(links4_RTs$rt_link) + 3 * sd(links4_RTs$rt_link))), ] 
  </code></pre>
  <p>I also tried it without lapply, but this too did not work.</p>
  <p>How can I delete every row where rt_link is &gt; or &lt; than 3SDs from the corresponding rt-mean (depending on the subject and condition)?</p>