'Summary for multiple / specific columns

I have a table with multiple columns and instead of running the summary on specific rows e.g. summary(a), summary(b) etc. I was wondering if there's a way to do it with a for loop.

In psuedo code, I'd look something like this:

list = [a, b, c] #where a,b,c are column names
for i in list:
    print(summary(i))


Solution 1:[1]

Appending to Ronak's answer; if you don't want to create an otherwise unneeded variable, you can subset the desired columns directly in the dataframe for a single-line solution:

summary(mtcars[c("mpg", "cyl")]

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1