Search code examples
rloopssummary

summary dataframe with loop in R


I have three dataframe: AAA, BBB, CCC I want to use see summary of each dataframe, instead of using

summary(AAA)
summary(BBB)
summary(CCC)

I wonder if I can use loop to solve this function, I tried the following lines, but didn' work

tables = list('AAA', 'BBB', 'CCC')
for (table in tables){
  summary(table)
}

Solution

  • You do not need a for loop necessarily, e.g.

    tables = list(mtcars, mtcars)
    purrr::map(tables, summary)
    
    lapply(tables, summary)