Hi: On Tue, Sep 14, 2010 at 11:13 AM, lord12 <gaut...@yahoo.com> wrote:
> > If you have 5 data frames and you append them to a list, how do you access > the first data frame, not the first value of the first data frame while > iterating in a for loop? > For a list named l, l[[1]] accesses the first component, or if you have it named df1, say, then l$df1. > list = c(d1,d2,d3,d4,d5) where d1..d5 are dataframes. > for(i in 1: length(list)){ > print(list[1]) > } > You wouldn't do it that way. Instead, l <- list(d1 = d1, d2 = d2, d3 = d3, d4 = d4, d5 =d5) # a named list l will print each component one after the other, or l$d1 will print the first component. BTW, it's not good form to name your objects after commonly used functions. Strange things can happen... Welcome to the wonderful world of subscripting in R :) See ?Extract for a brief, concise description. HTH, Dennis -- > View this message in context: > http://r.789695.n4.nabble.com/extracting-objects-from-lists-tp2539412p2539412.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. > [[alternative HTML version deleted]] ______________________________________________ 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.