title: R: Calculate correlation for a subset of my dataset?
body: <p>I have a dataset with 20 variables v1 - v20. Now I'd like to use cor(...) to calculate the correlation between v2 and v10 until v15 and v3 and v10 until v15. What's the best way to do this? Do I have to do this for each variable pair using</p>
  
  <pre><code>cor(v2, v10)
  cor(v2, v11)
  cor(v2, v12)
  and so on?
  </code></pre>
  
  <p>Here is the actual dataset:</p>
  
  <pre><code>   &gt; dput(dataset)
  structure(list(Number = 1:15, Question.1.1 = c(3L, 4L, 5L, 5L, 
  4L, 5L, 5L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L), Question.1.2 = c(1L, 
  2L, 1L, 1L, 4L, 1L, 1L, 2L, 3L, 1L, 1L, 1L, 1L, 1L, 1L), Question.2.1 = c(5L, 
  3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), Question.2.2 = c(2L, 
  1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Question.3.1 = c(2L, 
  NA, 4L, 5L, 4L, 3L, 5L, 3L, 5L, 5L, 5L, 5L, 4L, 4L, 4L), Question.3.2 = c(2L, 
  NA, 1L, 1L, 2L, 2L, 1L, 4L, 3L, 1L, 1L, 1L, 2L, 2L, 1L), Question.4.1 = c(3L, 
  2L, 5L, 2L, 5L, 5L, 5L, 3L, 5L, 5L, 5L, 5L, 4L, 5L, 2L), Question.4.2 = c(2L, 
  2L, 1L, 2L, 2L, 1L, 2L, 3L, 3L, 1L, 1L, 1L, 1L, 1L, 4L), Question.5.1 = c(5L, 
  3L, 5L, 3L, 4L, 4L, 5L, 3L, 5L, 5L, 5L, 5L, 5L, 4L, 4L), Question.5.2 = c(2L, 
  2L, 1L, 1L, 3L, 2L, 1L, 3L, 4L, 1L, 1L, 1L, 1L, 1L, 1L), Question.6.1 = c(5L, 
  2L, 2L, 2L, 3L, 2L, 3L, 1L, 3L, 3L, 5L, 4L, 3L, 3L, 1L), Question.6.2 = c(2L, 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 5L, 5L, 4L, 4L, 5L, 5L, 5L, 5L, 4L, 4L), Feature.7 = c(5L, 
  3L, 2L, 5L, 4L, 5L, 3L, 5L, 4L, 5L, 5L, 5L, 5L, 4L, 4L)), .Names = c("Number", 
  "Question.1.1", "Question.1.2", "Question.2.1", "Question.2.2", 
  "Question.3.1", "Question.3.2", "Question.4.1", "Question.4.2", 
  "Question.5.1", "Question.5.2", "Question.6.1", "Question.6.2", 
  "Question.7.1", "Question.7.2", "Question.8.1", "Question.8.2", 
  "Question.9.1", "Question.9.2", "AQ.1", "AQ.2", "Task.1", "Task.2", 
  "Task.3", "Task.4", "Task.5", "GQ.1", "GQ.2", "GQ.3", "GQ.4", 
  "GQ.5", "GQ.6", "GQ.7", "GQ.8", "GQ.9", "GQ.10", "Feature.1", 
  "Feature.2", "Feature.3", "Feature.4", "Feature.5", "Feature.6", 
  "Feature.7"), class = "data.frame", row.names = c(NA, -15L))
  </code></pre>