placing mean,total and max together in a table in r

前端 未结 3 1846
终归单人心
终归单人心 2021-01-21 15:21

I have some simple commands looking into totals, means and maximums of a variable whilst another variable is an assigned value:

sum(data[data$var1==1,]$var2)
mea         


        
3条回答
  •  孤街浪徒
    2021-01-21 16:08

    Look at the tables package, read through the vignette for the package shows how to do exactly what you are asking for.

    > tabular( ( factor(cyl) + 1) ~ mpg * (sum + mean + max), data=mtcars )
    
                 mpg             
     factor(cyl) sum   mean  max 
     4           293.3 26.66 33.9
     6           138.2 19.74 21.4
     8           211.4 15.10 19.2
     All         642.9 20.09 33.9
    

提交回复
热议问题