0

Surprisingly, I found little useful help via a google search even though I was sure that a code like this certainly has to exist.

What I want to do: create a empty dataframe with n (in my case n=100) colums in order that I can fill them up with a foor loop formula in the next step.

The dummy way of doing it would be of course to:

df <- cbind(df1, V3=NA, V4=NA, V5=NA, V6=NA, V7=NA, V8=NA, V9=NA, V10=NA, V11=NA, V12=NA, VA13=NA, V14=NA, V15=NA, V16=NA, V17=NA, V18=NA, V19=NA, V20=NA, V21=NA, V22=NA, V23=NA, V24=NA, V25=NA, V26=NA, VA27=NA, V28=NA, V29=NA, V30=NA ... -> V100 = NA)

But is there a better way of doing this?

  • when I googled how to do it for multiple colums I only came up with cbind or dplyr solutions that all need to have a lot of inputs such as in the example above
  • See linked post for more options: `data.frame(matrix(NA, ncol = 5))`, or drop the NA row, so dataframe is empty: `data.frame(matrix(NA, ncol = 5))[0, ]` – zx8754 Feb 01 '23 at 14:17

0 Answers0