I try to run my code but always receive the following error message:
Fehler in `[<-.data.frame`(`*tmp*`, , i, value = list(`NOVN SW Equity PX_LAST` = c(6.54, : new columns would leave holes after existing columns
My code looks as following
library(tidyverse)
Daten_bloomberg <- read_excel("~/Desktop/master thesis topics/Data for R/Daten_bloomberg.xlsx", na = "NA")
Event <- read_excel("~/Desktop/master thesis topics/Data for R/Event.xlsx", col_types = c("numeric", "text"))
Daten_bloomberg <- as.data.frame(sapply(Daten_bloomberg, as.numeric))
Daten_bloomberg[is.na(Daten_bloomberg)] <- NA
Data_last_price <- data.frame(Data1 = rep(1,7875) )
for (i in 1:133) {
EventTicker <- as.character(Event[i,2])
EventTicker1 <- paste(as.character(Event[i,2]) , "PX_Last")
Data1 <- select(Daten_bloomberg , contains(EventTicker1))
Data_last_price[,i] <- rep(Data1,1)
}
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.
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?