Suppose I have a dataframe with 16 variables named : Amount_day_1, Amount_day_2 .. I would like to take the mean of each
What I thought of doing is :
for (i in 1:16){
!!as.name(paste0("Mean_Amount_Day_", i) <-
mean(df$!!as.name(paste0("Amount_Day_", i)))
}
But it really does not work. In fact I really don't know how to select a variable with the dollar sign if it is within a for
loop?