title: For loops to plot two outputs in sequence in R
body: <p>I'm trying to write a double <code>for</code> loop to plot two outputs in sequence. </p>
  
  <p>Based on the two following vectors:</p>
  
  <pre><code>vec.a &lt;- c("a1", "a2", "a3")
  vec.b &lt;- c("b1", "b2", "b3")
  </code></pre>
  
  <p>I tried the first loop:</p>
  
  <pre><code>for (i in vec.a){
      cat(i)
      for (j in vec.b){
          cat(j, "| ")
      }
  }
  </code></pre>
  
  <p>And the output was:</p>
  
  <p><code>a1b1 | b2 | b3 | a2b1 | b2 | b3 | a3b1 | b2 | b3 |</code></p>
  
  <p>I tried a second loop:</p>
  
  <pre><code>for (i in vec.a){
      for (j in vec.b){
          cat(i)
          cat(j, "| ")
      }
  }
  </code></pre>
  
  <p>And the output was:</p>
  
  <p><code>a1b1 | a1b2 | a1b3 | a2b1 | a2b2 | a2b3 | a3b1 | a3b2 | a3b3 |</code></p>
  
  <p><strong>But the output desired is:</strong></p>
  
  <p><code>a1b1 | a2b2 | a3b3</code></p>
  
  <p>How to do this?</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I want to compare the graphics between the columns in the same position of the two data frames. But the sequence shown is not that I desire. I think that the logic is the same of the example above. </p>
  
  <pre><code>set.seed(99)
  df.a &lt;- matrix(rnorm(50), 10, 10,  # 10 rows and 10 columns
             dimnames=list(paste("p", 1:10, sep = ""), 
                           paste("sp.A", 1:10, sep = ""))) 
  
  df.b &lt;- matrix(rnorm(50), 20, 10,  # 20 rows and 10 columns
             dimnames=list(paste("p", 1:20, sep = ""), 
                           paste("sp.B", 1:10, sep = ""))) 
  </code></pre>
  
  <p>To compare the graphics, I used something like this:</p>
  
  <pre><code>par(mfrow = c(1,2))
  invisible(lapply(colnames(df.a[ ,1:ncol(df.a)]), function(x){
     invisible(lapply(colnames(df.b[ ,1:ncol(df.b)]), function(w){
       plot(df.a[ ,x], main = x) 
       plot(df.b[ ,w], main = w)
     }))
  }))
  </code></pre>
  
  <p>How to plot the first column of the <code>df.a</code> paired with the first column of the <code>df.b</code>, and so on? </p>