Descriptive statistics (mtcars data)
FirstQuantile <- function(X){
FQ <- quantile(X, .25)
return(FQ)
}
SecondQuantile <- function(X){
FQ <- quantile(X, .75)
return(FQ)
}
Descriptive <- function(y){
tmp <- do.call(data.frame,
list( n = apply(y, 2, length),
min = apply(y, 2, min, na.rm=T),
P25th = apply(y, 2, FirstQuantile),
mean = apply(y, 2, mean, na.rm=T),
median = apply(y, 2, median, na.rm=T),
P75th = apply(y, 2, SecondQuantile),
max = apply(y, 2, max, na.rm=T)))
return(tmp)
}
|
|
n
|
min
|
P25th
|
mean
|
median
|
P75th
|
max
|
|
mpg
|
32
|
10.40
|
15.43
|
20.09
|
19.20
|
22.80
|
33.90
|
|
cyl
|
32
|
4.00
|
4.00
|
6.19
|
6.00
|
8.00
|
8.00
|
|
disp
|
32
|
71.10
|
120.83
|
230.72
|
196.30
|
326.00
|
472.00
|
|
hp
|
32
|
52.00
|
96.50
|
146.69
|
123.00
|
180.00
|
335.00
|
|
drat
|
32
|
2.76
|
3.08
|
3.60
|
3.70
|
3.92
|
4.93
|
|
wt
|
32
|
1.51
|
2.58
|
3.22
|
3.33
|
3.61
|
5.42
|
|
qsec
|
32
|
14.50
|
16.89
|
17.85
|
17.71
|
18.90
|
22.90
|
|
vs
|
32
|
0.00
|
0.00
|
0.44
|
0.00
|
1.00
|
1.00
|
|
am
|
32
|
0.00
|
0.00
|
0.41
|
0.00
|
1.00
|
1.00
|
|
gear
|
32
|
3.00
|
3.00
|
3.69
|
4.00
|
4.00
|
5.00
|
|
carb
|
32
|
1.00
|
2.00
|
2.81
|
2.00
|
4.00
|
8.00
|
Correlation matrix
Example with GGally
library(GGally)
ggpairs(mtcars)

Example with corrplot
library(corrplot)
data_1 <- data %>% select(-X)
df_cor <- cor(data_1, use = "pairwise.complete.obs")
corrplot(df_cor)
