sapply(names(list1), function(.data.){ with(list1[[.data.]], plot(x, y, type='l', main=paste("Graphic of", .data))) })
On Fri, Oct 30, 2009 at 3:41 AM, Kenneth Roy Cabrera Torres <krcab...@une.net.co> wrote: > Hi R users: > > I got this code to generate a graphic for each member of a lists. > > list1<-list(A=data.frame(x=c(1,2),y=c(5,6)),B=data.frame(x=c(8,9),y=c(12,6))) > names1<-names(list1) > sapply(1:length(list1),function(i) > with(list1[[i]],plot(x,y,type="l",main=paste("Graphic of",names1[i])))) > > Is there a more elegant solution for not to use two separate lists? > > I would like to just use > > sapply(list1, somePlotfunction) > > and plot for each graphic in the title have the name of the member of > the list. > > Thank you for your help. > > Kenneth > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve? ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.