I would like to create an empty dataframe and therefore perform a loop and add the new content to a (new) dataframe.
Therefore I wrote something like this:
number <- c(1,2)
text <- c("Yes", "No")
df_test <- data.frame(number, text)
df_base = data.frame(number = numeric(), text = character())
for(i in 1:nrow(df_test)){
text <- df_test$text[i]
number <- df_test$number[i]
df_temp <- data.frame(text, number)
df_base <- rbind(df_base, df_temp)
}
Code above does the trick but does not seem to be the most efficient way. Any thoughts on how I can write this better?