title: Finding if the values in one column are within the range of several other columns
body: <p>I am looking for an easy way to find whether the value in a column lies within the range of values in other columns.</p>
  <p>My input looks like this:</p>
  <pre><code>ID  &quot;Q1 Comm - 01 Scope Thesis&quot; &quot;Q1 Comm - 02 Scope Project&quot; &quot;Q1 Comm - 03 Learn Intern&quot;    &quot;Q1 Comm - 04 Biography&quot;    &quot;Q1 Comm - Overall Plan&quot;
  10   NA                          NA                           4                              NA      4
  31   2                           NA                           NA                             NA      2
  225  0                           NA                           NA                             NA      1
  243  NA                          2                            NA                             1       0
  310  NA                          2                            NA                             1       NA
  </code></pre>
  <p>For each unique <code>ID</code>, I am interested in identifying when the column <code>Q1 Comm - Overall Plan</code> is:</p>
  <p>1 - <code>Below</code> the <code>min()</code> of all the other columns, or</p>
  <p>2 - <code>Above</code> the <code>max()</code> of all the other columns, or</p>
  <p>3 - <code>Within</code> the range of all the other columns</p>
  <p>The complete list of columns (along with the <code>overall</code> column) is below:</p>
  <pre><code>&quot;Q1 Comm - 01 Scope Thesis&quot;
  &quot;Q1 Comm - 02 Scope Project&quot;
  &quot;Q1 Comm - 03 Learn Intern&quot;
  &quot;Q1 Comm - 04 Biography&quot;
  &quot;Q1 Comm - 05 Exhibit&quot;
  &quot;Q1 Comm - 06 Social Act&quot;
  &quot;Q1 Comm - 07 Post Project&quot;
  &quot;Q1 Comm - 08 Learn Plant&quot;
  &quot;Q1 Comm - 09 Study Narrate&quot;
  &quot;Q1 Comm - 10 Learn Participate&quot;
  &quot;Q1 Comm - 11 Write 1&quot;
  &quot;Q1 Comm - 12 Read 2&quot;
  &quot;Q1 Comm - Overall Plan&quot;
  </code></pre>
  <p>My required output is something like this:</p>
  <pre><code>ID  &quot;Q1 Comm - 01 Scope Thesis&quot; &quot;Q1 Comm - 02 Scope Project&quot; &quot;Q1 Comm - 03 Learn Intern&quot;    &quot;Q1 Comm - 04 Biography&quot;    &quot;Q1 Comm - Overall Plan&quot; &quot;Q1_check&quot;
  10   NA                          NA                           4                              NA      4 &quot;within&quot;
  31   2                           NA                           NA                             NA      2 &quot;within&quot;
  225  0                           NA                           NA                             NA      1 &quot;above&quot;
  243  NA                          2                            NA                             1       0 &quot;below&quot;
  310  NA                          2                            NA                             1       NA NA
  </code></pre>
  <p>The dput() for my data frame <code>df</code> is below.</p>
  <pre><code>dput(df)
  
  structure(list(ID = c(10L, 31L, 225L, 243L), Q1.Comm...01.Scope.Thesis = c(NA, 
  2L, 0L, NA), Q1.Comm...02.Scope.Project = c(NA, NA, NA, 2L), 
      Q1.Comm...03.Learn.Intern = c(4L, NA, NA, NA), Q1.Comm...04.Biography = c(NA, 
      NA, NA, 1L), Q1.Comm...Overall.Plan = c(4L, 1L, 2L, 
      NA), X = c(NA, NA, NA, NA), X.1 = c(NA, NA, NA, NA), X.2 = c(NA, 
      NA, NA, NA)), class = &quot;data.frame&quot;, row.names = c(NA, -4L
  ))
  </code></pre>
  <h4>Note:</h4>
  <p>I had asked this question here <a href="https://stackoverflow.com/questions/67898633/finding-if-a-value-is-within-the-range-of-other-columns/67899154#67899154">Finding if a value is within the range of other columns</a> but the example was too simplified and none of the solutions worked for me.</p>
  <p>The question was getting too lengthy, therefore, for the sake of clarity, I am posting this as a new question.</p>
  <p>I thank you for your time and help on this post.</p>