How to obtain summary statistics in R