How to initialize empty data frame (lot of columns at the same time) in R

Maybe this –

df <- data.frame(matrix(ncol = 10000, nrow = 0))
colnames(df) <- paste0("hello", c(1:10000))

And @joran’s suggestion – df <- setNames(data.frame(matrix(ncol = 10000, nrow = 0)),paste0("hello", c(1:10000)))

Leave a Comment