I have a numeric vector, say new_cols <- c(10, 20, 30)
, and I want to add new empty columns to an existing tibble where the column names are take from the above list. Even though the native data.frame
doesn't support numeric columns, I can get away with it using tibble.
The answer given in this question provides df[new_cols]
as the solution but it wouldn't work with numeric vector.
Currently I'm looping through the vector and creating new columns using mutate, there must be a more elegant way to do this using tidyverse.