df_a <- data.frame(matrix(nrow = 4,ncol = 4,1))
df_b <- data.frame(matrix(nrow = 4,ncol = 4,2))
df_c <- data.frame(matrix(nrow = 4,ncol = 4,3))
colnames(df_a) <- colnames(df_b) <- colnames(df_c) <- c("q_1","q_2","q_3")
avg_a <- data.frame(matrix(nrow = 1,ncol = 4))
colnames(avg_a) <- c("q_1","q_2","q_3","q_4")
alph <- c("a","b","c")
I have made 3 datasets and I want to collect averages of all columns of each table in another table. For example average of all columns of df_a
will be stored in avg_a
. How can I write a loop using alph
vector and select datasets in the loop and create dataframes in the loop? I know that using
assign(paste("avg_",alph[i],sep = ""),data.frame(matrix(nrow = 1,ncol = 4)))
allows me to generate average table specific to dataset. but then how I refer to this table such that, for example, each column of avg_a
table will have averages from df_a
table?