I have the following setup
df_names <- c("df1", "df2", "df3")
df1 <- tibble("1" = "hallo")
df2 <- tibble("1" = "hallo")
df3 <- tibble("1" = "hallo")
missing_columns <- c("2", "3")
My goal is to add to each data frame the columns seen in missing_columns.
I tried
for(i in df_names){
for(j in missing_columns){
get(i)[, j] <- ""
}
}
Error in get(i) <- `*vtmp*` : could not find function "get<-"
and
for(i in df_names){
for(j in missing_columns){
assign(get(i)[, j], "")
}
}
Error: Can't subset columns that don't exist.
x Column `2` doesn't exist.
Ofcourse column 2 does not exist, that's why i want to add it.
df1[["2"]] <- "foo"