title: R Error: new columns would leave holes after existing columns; How to solve this?
body: <p>I try to run my code but always receive the following error message:</p>
  <blockquote>
  <p><code>Fehler in `[&lt;-.data.frame`(`*tmp*`, , i, value = list(`NOVN SW Equity PX_LAST` = c(6.54,  :  new columns would leave holes after existing columns</code></p>
  </blockquote>
  <p>My code looks as following</p>
  <pre><code>library(tidyverse)
  Daten_bloomberg &lt;- read_excel(&quot;~/Desktop/master thesis topics/Data for R/Daten_bloomberg.xlsx&quot;, na = &quot;NA&quot;)
  Event &lt;- read_excel(&quot;~/Desktop/master thesis topics/Data for R/Event.xlsx&quot;, col_types = c(&quot;numeric&quot;, &quot;text&quot;))
  Daten_bloomberg &lt;- as.data.frame(sapply(Daten_bloomberg, as.numeric)) 
  Daten_bloomberg[is.na(Daten_bloomberg)] &lt;- NA
  
  Data_last_price &lt;- data.frame(Data1 = rep(1,7875) )
  
  for (i in 1:133) {
    EventTicker &lt;-  as.character(Event[i,2])
    EventTicker1 &lt;- paste(as.character(Event[i,2]) , &quot;PX_Last&quot;) 
    Data1 &lt;- select(Daten_bloomberg , contains(EventTicker1))
    Data_last_price[,i] &lt;- rep(Data1,1)
  }
  </code></pre>
  <p>With that Code I basically try to make a new dataframe with columns containing the ticker and the string PX_Last. Daten_bloomberg contains 7875 rows and 884 variables. Event contains 133 observations and two variables.</p>
  <p>However, always when I run this loop the above error message is occuring and the loop stops at position 87. I guess the problem is that the columns in the Dataset Daten_bloomberg contains a lot of NA Values. But I do not know how i can solve that problem. Has anyone an idea?</p>