title: calculating correlations between columns with different lengths in R
body: <p>I have a data frame with 14 columns and I want to calculate the correlations between these columns. However, there are NA's in some of the columns. Initially, I used na.omit(a) to remove the NA from the data frame and then used cor to calculate the correlations, but doing na.omit removed most of my observations due to 5 columns which are mostly NA's. </p>
  
  <p>Currently, I am trying to use a For Loop to go through individually select a column,use na.omit,calculate the correlations, and put the value in a array. I will repeat this process for all the variables. Below is a sample of the data and a sample of my code. </p>
  
  <pre><code>head(selected_data)
  
  final initial qualitative quantitative Revenue
   NA     1        2           11           2 
    1    NA        4           3           NA 
   NA    NA        8           NA          NA 
   8     7         9           6            3
  
  a=na.omit(selected_data$final)
  b=na.omit(selected_data$initial)
  c=na.omit(selected_data$qualitative)
  d=na.omit(selected_data$quantitative)
  e=na.omit(selected_data$Revenue)
  
  
        col_name =c('a', 'b' ,'c', 'd', 'e')
     i="a"
     j="a"
     for (i in col_name) {
         for (j in col_name) {
            Rating_array&lt;-cor(i,j)
    }
  }
  </code></pre>
  
  <p>Unfortunately, loop isn't working. I am new to R and I am open to a better approach. I would appreciate for any help that is provided.</p>