r - Summaries for many Lists -


instead of writing summary(...) each list tried following code:

test <- c('list1', 'list2') summary(test) 

since guess r functions read objects , objects vectors thought work not. knows why not working , how can summaries of lists in 1 command?

you can use lapply loop on every element in list

#sample data test <- list(mtcars, iris) lapply(test, summary)  #[[1]] #  mpg             cyl             disp             hp             drat       #min.   :10.40   min.   :4.000   min.   : 71.1   min.   : 52.0   min.   :2.760   #1st qu.:15.43   1st qu.:4.000   1st qu.:120.8   1st qu.: 96.5   1st qu.:3.080   #median :19.20   median :6.000   median :196.3   median :123.0   median :3.695   #mean   :20.09   mean   :6.188   mean   :230.7   mean   :146.7   mean   :3.597   #3rd qu.:22.80   3rd qu.:8.000   3rd qu.:326.0   3rd qu.:180.0   3rd qu.:3.920   #max.   :33.90   max.   :8.000   max.   :472.0   max.   :335.0   max.   :4.930   #    wt             qsec             vs                            gear       # min.   :1.513   min.   :14.50   min.   :0.0000   min.   :0.0000   min.   :3.000   #1st qu.:2.581   1st qu.:16.89   1st qu.:0.0000   1st qu.:0.0000   1st qu.:3.000   #median :3.325   median :17.71   median :0.0000   median :0.0000   median :4.000   #mean   :3.217   mean   :17.85   mean   :0.4375   mean   :0.4062   mean   :3.688   #3rd qu.:3.610   3rd qu.:18.90   3rd qu.:1.0000   3rd qu.:1.0000   3rd qu.:4.000   #max.   :5.424   max.   :22.90   max.   :1.0000   max.   :1.0000   max.   :5.000   #    carb       #min.   :1.000   #1st qu.:2.000   #median :2.000   #mean   :2.812   #3rd qu.:4.000   #max.   :8.000    #[[2]] #  sepal.length    sepal.width     petal.length    petal.width          species   # min.   :4.300   min.   :2.000   min.   :1.000   min.   :0.100   setosa    :50   # 1st qu.:5.100   1st qu.:2.800   1st qu.:1.600   1st qu.:0.300   versicolor:50   # median :5.800   median :3.000   median :4.350   median :1.300   virginica :50   # mean   :5.843   mean   :3.057   mean   :3.758   mean   :1.199                   # 3rd qu.:6.400   3rd qu.:3.300   3rd qu.:5.100   3rd qu.:1.800                   # max.   :7.900   max.   :4.400   max.   :6.900   max.   :2.500           

as per comment @docendo discimus,

if op has taken lists in form of character mentioned in question.

test <- c('list1', 'list2') 

in case mget should used

lapply(mget(test), summary) 

Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -