R functions to Summarize Data

Reading the .csv file into R

# reading the data
mtcars <- read.csv("mtcars.csv")

Get the number of rows and columns (dimensions) of the imported data

# dimensions of the data frame
dim(mtcars)
[1] 32 12

List the column names in the dataframe

colnames(mtcars)
 [1] "X"    "mpg"  "cyl"  "disp" "hp"   "drat" "wt"   "qsec" "vs"   "am"  
[11] "gear" "carb"

Attach the dataframe

attach(mtcars)

Measure the mean, variance and standard deviation of the mpg in the dataframe mtcars

mean(mtcars$mpg)
[1] 20.09062
var(mtcars$mpg)
[1] 36.3241
sd(mtcars$mpg)
[1] 6.026948

Measure the median of the mpg in the dataframe mtcars

median(mtcars$mpg)
[1] 19.2

Measure the minimum value of mpg in the dataframe mtcars

min(mtcars$mpg)
[1] 10.4

Measure the maximum value of mpg in the dataframe mtcars

max(mtcars$mpg)
[1] 33.9

Measure the range of mpg in the dataframe mtcars

range(mtcars$mpg)
[1] 10.4 33.9

Display a summary of the mpg in the dataframe mtcars using summary()

summary(mtcars$mpg)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  10.40   15.43   19.20   20.09   22.80   33.90 

Display a summary of the mpg in the dataframe mtcars using describe()

library(psych)
describe(mtcars$mpg)
   vars  n  mean   sd median trimmed  mad  min  max range skew kurtosis   se
X1    1 32 20.09 6.03   19.2    19.7 5.41 10.4 33.9  23.5 0.61    -0.37 1.07