I have an existing R dataframe that is filled out. I want to enter in new information in a series of new columns. If I have a list of the column names, is there an easy way to form all these empty columns?
I will then fill out the entries based on outputs of later calculations
MWE
animal = c("echidna", "kangaroo", "emu")
age = c(3, 7, 4)
df <- data.frame(animal, age)
newColumns = c("pen", "colour", "sex")
I know I can do
df$pen = NA
df$colour = NA
df$sex = NA
but since I have the list, and it's long - is there an efficient way to do this?