title: R - How to remove NAs when using ASSIGN with a FOR LOOP?
body: <p>I have some code which imports a data frame (keywordsDF), and whilst using a FOR LOOP, it (by using the colnames), creates new variables depending on how many columns there are in it:</p>
  
  <pre><code>keywordsDF = read_excel("//Users//n//Desktop//Keywords.xlsx")
  
  keywordList = colnames(keywordsDF)
  
  for (i in seq_along(keywordList)) {
    assign(keywordList[i], keywordsDF[keywordList[i]])
  }
  </code></pre>
  
  <p>This all works fine. However, as the columns are of a different length, it imports NAs into the data.</p>
  
  <p><br></p>
  
  <p>I would normally remove those NAs for each column like:</p>
  
  <p><code>consumption = keywordsDF$Consumption[!is.na(keywordsDF$Consumption)]</code></p>
  
  <p><br>
  But I am not sure how to do it in the FOR LOOP (where I don't know the column names). I.e. where do I put the <code>!is.na</code>? As nothing seems to work for me.</p>