I am trying to determine the mean of multiple vectors. Is there a more efficient alternative than using assign within a loop to calculate the means, as I do below?
a=c(1,2,3,4)
b=c(1,3,4,3,4)
c=c(3,9,4,2,7,3,7)
for (i in c("a","b","c")) {
assign(paste(i,"mean", sep = ""), mean(get(i)))
}
list2env('names<-'(lapply(list(a,b,c), mean), paste0(c('a', 'b', 'c'),'mean')),.GlobalEnv)Although you should learn to work with lists to avoid this syntax