Here is one way to do this:
tmp.df <- data.frame(col_1=rnorm(10),col_2=rnorm(10),col_3=rnorm(10)) x <- seq(2,20,by=2) plot(x, tmp.df$col_1) for(j in 2:3){ name.list <- list("x",paste("col_",j,sep="")) with(tmp.df, do.call("lines",lapply(name.list,as.name))) }
You can also do colnames (tmp.df) [j] instead of pasting (..) if you want.
source share