I got a list of data frames, such as c(df01,df02,df03)
.
Each data frame has three columns, c("A", "B", "C")
.
I want to write a for loop to modify each column for each data frame. I tried:
for (df in c("df01", "df02", "df03")) {
for (col in c("A", "B", "C")) {
get(df)[[col]] <- 0
}
}
I learned from this post that we cannot assign value to the result of the get() function in R.
I also tried
assign(df[[col]], 0)
But this also does not work. The assign()
function only assigns a value to a name, but here df[[col]]
is not a name, but a column.
How can I fix this?