##1 #Un dataset que contenga mínimo diez (10) ymáximo 15 variables continuas. No utilizar ni Titanic ni Iris

library(readr)
library(dplyr)
India_Menu <- read_csv("India_Menu.csv")
DT::datatable(India_Menu)
sapply(India_Menu, function(x) sum(is.na(x)))
##          Menu Category             Menu Items         Per Serve Size 
##                      0                      0                      0 
##          Energy (kCal)            Protein (g)          Total fat (g) 
##                      0                      0                      0 
##            Sat Fat (g)          Trans fat (g)      Cholesterols (mg) 
##                      0                      0                      0 
## Total carbohydrate (g)       Total Sugars (g)       Added Sugars (g) 
##                      0                      0                      0 
##            Sodium (mg) 
##                      1
India_Menu1<-India_Menu %>% select_if(is.numeric)
India_Menu1
library(ggplot2)
ggplot(India_Menu1,aes(y=`Sodium (mg)`))+geom_boxplot(fill="blue")
## Warning: Removed 1 rows containing non-finite values (stat_boxplot).

India_Menu1$`Sodium (mg)`[is.na(India_Menu1$`Sodium (mg)`)] <- 152.025
fig1=ggplot(India_Menu1,aes(y=`Energy (kCal)`))+geom_boxplot(fill="red")
fig2=ggplot(India_Menu1,aes(y=`Protein (g)`))+geom_boxplot(fill="4")
fig3=ggplot(India_Menu1,aes(y=`Total fat (g)`))+geom_boxplot(fill="5")
fig4=ggplot(India_Menu1,aes(y=`Sat Fat (g)`))+geom_boxplot(fill="6")
fig5=ggplot(India_Menu1,aes(y=`Trans fat (g)`))+geom_boxplot(fill="7")
fig6=ggplot(India_Menu1,aes(y=`Cholesterols (mg)`))+geom_boxplot(fill="8")
fig7=ggplot(India_Menu1,aes(y=`Total carbohydrate (g)`))+geom_boxplot(fill="9")
fig8=ggplot(India_Menu1,aes(y=`Total Sugars (g)`))+geom_boxplot(fill="10")
fig9=ggplot(India_Menu1,aes(y=`Added Sugars (g)`))+geom_boxplot(fill="11")
fig10=ggplot(India_Menu1,aes(y=`Sodium (mg)`))+geom_boxplot(fill="12")
library(gridExtra)
## 
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
## 
##     combine
grid.arrange(fig1, fig2, fig3, fig4, fig5,ncol=5, widths=c(2,2,2,2,2))

grid.arrange(fig6, fig7, fig8, fig9, fig10,ncol=5, widths=c(2,2,2,2,2))

##2 #Calcular el vector de medias:

medias=colMeans(India_Menu1)
medias2=knitr::kable(round(colMeans(India_Menu1),2))
medias2
x
Energy (kCal) 244.64
Protein (g) 7.49
Total fat (g) 9.99
Sat Fat (g) 5.00
Trans fat (g) 0.69
Cholesterols (mg) 26.35
Total carbohydrate (g) 31.19
Total Sugars (g) 15.46
Added Sugars (g) 10.34
Sodium (mg) 360.57

##3 #Calcular la matriz de varianzas y correlaciones

sigma1=cov(India_Menu1)
sigma=knitr::kable(round(cov(India_Menu1),2))
sigma
Energy (kCal) Protein (g) Total fat (g) Sat Fat (g) Trans fat (g) Cholesterols (mg) Total carbohydrate (g) Total Sugars (g) Added Sugars (g) Sodium (mg)
Energy (kCal) 34430.60 1279.07 1743.27 726.03 95.55 3543.38 3117.90 184.31 9.64 74167.01
Protein (g) 1279.07 69.50 75.48 28.71 9.98 247.59 71.32 -37.00 -38.01 3507.47
Total fat (g) 1743.27 75.48 106.91 42.73 10.36 220.84 114.70 -35.71 -41.42 4246.33
Sat Fat (g) 726.03 28.71 42.73 24.01 -2.37 89.57 53.09 -3.88 -12.20 1474.39
Trans fat (g) 95.55 9.98 10.36 -2.37 40.02 -9.45 -16.06 -8.17 -6.07 460.46
Cholesterols (mg) 3543.38 247.59 220.84 89.57 -9.45 2533.53 148.12 -162.45 -162.19 11196.56
Total carbohydrate (g) 3117.90 71.32 114.70 53.09 -16.06 148.12 424.44 164.44 133.91 4823.50
Total Sugars (g) 184.31 -37.00 -35.71 -3.88 -8.17 -162.45 164.44 246.18 204.43 -2202.60
Added Sugars (g) 9.64 -38.01 -41.42 -12.20 -6.07 -162.19 133.91 204.43 204.02 -1832.25
Sodium (mg) 74167.01 3507.47 4246.33 1474.39 460.46 11196.56 4823.50 -2202.60 -1832.25 222594.58
install.packages("corrplot")
library(corrplot)
correlacion<-round(cor(India_Menu1), 1)

corrplot(correlacion, method="number", type="upper")

##4 #Calcular las distancias de Mahalanobis

distancias<-mahalanobis(India_Menu1,medias,sigma1)
distancias
##   [1]   7.7715429   7.3972336  21.9474785  15.6891818   4.2764135  15.2760358
##   [7]   4.5046205   1.8288603   5.5718160   5.8027904   6.2931401   7.7230411
##  [13]  21.3736031   5.8863861   5.2228623   2.1583219  20.5758539  23.6162399
##  [19]  46.2521269  10.3707955   3.2446079   5.4359723  11.3800270  12.7118237
##  [25]  26.8860505 138.9746455   5.7754968  10.1877938  19.7086324   3.5168925
##  [31]   5.8081434  11.1030173   2.8953294   3.8772010  25.8659358  30.0331383
##  [37]   9.1198964   4.8233106  22.1671964   7.5097810  41.4516624  23.5749682
##  [43]   9.3503205   3.0889663   2.7224732   1.9428674   2.7224732   2.5883933
##  [49]   2.5768024   2.0114781   3.4323920   5.0398011   2.5517705   3.7065859
##  [55]   5.7923366   3.1903390   4.9892153   7.0595154   1.8710374   3.2900454
##  [61]   5.8175449   0.9376713   2.9579467   5.4683625  11.1062542  11.6752933
##  [67]  19.4222777   3.1270531   3.1611799   3.2673119   2.4519897   2.4740439
##  [73]   2.7214586   2.4225710   2.4364605   2.6635777   2.0564453   1.5268637
##  [79]   1.5105067   1.1325324  11.3709766  12.5145410  17.4090307   2.9258488
##  [85]   2.9122238   2.6448445   3.4341308   1.6815086   1.6237342   2.5564579
##  [91]   0.7267619   9.7457055   0.9592374   1.8840158   0.8400364   1.3598806
##  [97]   0.8093031   1.1779626   0.8716910   4.6066292   1.5701683  10.1986951
## [103]   0.7784908   0.6852946  13.4865559  13.3335529  12.6658876  20.5145675
## [109]  32.3102510  36.5677903  19.3017852  60.0654793  14.0092746   1.9855692
## [115]   3.6451558   2.7334059   4.8018042  10.5594874   3.5909358   6.8800857
## [121]  15.5701824   2.4199506   3.9839057   8.5123270   3.1463342   5.8087067
## [127]  12.9950636   1.5565543   1.9863625   1.7557271   3.2094369   3.1199204
## [133]   5.3315273   2.4851339   2.9486534   9.3817330 125.5965899   3.4279587
## [139]   3.2825940   2.1990082   7.6895484
summary(distancias)
##     Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
##   0.6853   2.5565   4.5046   9.9291  11.1030 138.9746