Nice summary table in R

I have a vector (column from an imported csv file) that I'd like to make some summary statistics from and put it in a table and put in a small report. Can R do this. So basically I have 12 columns (1 for each dataset and in the created table I want them as rows) and for each, I'd like to calculate mean, min, max, coefficient of varation, sd, kurtosis, etc... What is a good way to do this?

Topic r

Category Data Science


This can be done like this for example:


library(plyr)
library(moments)

mydata <- data.frame(data1=c(12,65,23,8), data2=c(98,54,76,27))

mysummary <- function(df) {
  ldply(colnames(df), function(col) {
    data.frame(data=col,
               mean=mean(df[,col]),
               min= min(df[,col]),
               max=max(df[,col]),
               stddev=sd(df[,col]),
               coeffvar=sd(df[,col])/mean(df[,col]),
               kurtosis=kurtosis(df[,col])
    )
  })
}
> mysummary(mydata)
   data  mean min max   stddev  coeffvar kurtosis
1 data1 27.00   8  65 26.11513 0.9672270 2.165576
2 data2 63.75  27  98 30.37954 0.4765419 1.686230

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.