title: Apply a condition to a for loop to plot over all dataframes R
body: <p>I am trying to conditionally output plots based on the values of a factor in multiple dataframes. My dataframes are "n310" and 323 additional dataframes "mrns[[i]]".</p>
  
  <p>I created categories for a variable in the n310 dataframe:</p>
  
  <pre><code>n310$ar.cat[n310$arousals_index_per_h_sleep &lt;= 14.9 &amp; n310$arousals_index_per_h_sleep != "NA"] &lt;- "LOW"
  n310$ar.cat[n310$arousals_index_per_h_sleep &gt; 14.9 &amp; n310$arousals_index_per_h_sleep &lt; 29.4] &lt;- "MED"
  n310$ar.cat[n310$arousals_index_per_h_sleep &gt;= 29.4] &lt;- "HIGH"
  </code></pre>
  
  <p>I added the categorical and continuous variables of n310 to mrns[[i]] by matching to the respective mrn variables:</p>
  
  <pre><code>for (i in 1:323) {
    mrns[[i]]$ar.value &lt;- n310$arousals_index_per_h_sleep[match(mrns[[i]]$raw.mrn, n310$mrn)]
    mrns[[i]]$ar.cat &lt;- n310$ar.cat[match(mrns[[i]]$raw.mrn, n310$mrn)]
  }
  </code></pre>
  
  <p>Then I tried to plot only the "LOW" category of mrns[[i]]$ar.cat:</p>
  
  <pre><code>for (i in 1:323) {
    if (mrns[[i]]$ar.cat == "LOW") {
      png(paste0(arIndLowSys, mrns[[i]]$raw.mrn, "_systolic_ar_index_low.png"), height=1600, width=1600, res=200, family="Times")
      plot(mrns[[i]]$raw.Hour, mrns[[i]]$raw.Systolic, main="Systolic Blood Pressure per Hour of Day", xlab="Hour of Day", ylab="Systolic Blood Pressure", family="Times", bty="L", xlim=c(0, 24), xaxp=c(0, 24, 12))
      mtext(mrns[[i]]$ar.value, side=4, line=0)
      mtext(mrns[[i]]$ar.cat, side=4, line=-1)
      dev.off()
  }}
  </code></pre>
  
  <p>And got the following errors:</p>
  
  <pre><code>Error in if (mrns[[i]]$ar.cat == "LOW") { : 
    missing value where TRUE/FALSE needed
  </code></pre>
  
  <p>There ARE "NA" or missing values of mrns[[i]]$ar.cat, so I'm not how to disregard those "NA" values when when producing the plots.</p>
  
  <p>Anyone have any suggestions?</p>
  
  <p>Thank you!</p>