I have a number of dfs to which I want to add a column. For the sake of a mrp, these dfs are called df_1, df_2, df_3...
for (i in 1:10) {
assign(paste("df_",i,sep = ""),data.frame(x = rep(1,10), y = rep(2,10)))
}
I want to add another column z to each of these dfs.
z <- rep("hello",10)
How can I accomplish this?
Using lapply I have been able to do this
q <- list()
for (i in 1:10) {
q[[i]] <- assign(paste("df_",i,sep = ""),data.frame(x = rep(1,10), y = rep(2,10)))
}
z <- rep("hello",10)
q <- lapply(q, cbind,z)
This adds the required column, however, I don't know how to preserve the names. How can I still have df_1, df_2, etc but each with a new column z?
Thanks in advance