juli g. pausas wrote: > Dear all, > How could I use variables in a loop that their names are in a vector? > For example: > > aaa <- 1:10 > bbb <- aaa*2 > ccc <- aaa+bbb > > varn <- c("aaa", "bbb", "ccc") > m <- rep(NA, 3) > > for (i in 1:length(varn)) m[i] <- mean(varn[i]) # wrong > > Use ?get. for (i in 1:length(varn)) m[i]=mean(get(varn[i])) # right sundar