# 1. Load File, use summary to get overview and get median and mean of two attributes
getwd()
## [1] "\\\\p2stg03/NYUsers/dquarshie/Documents/R Class"
LifeCycleSavings <- read.csv("LifeCycleSavings.csv", header = TRUE)
LifeCycleSavings
## X sr pop15 pop75 dpi ddpi
## 1 Australia 11.43 29.35 2.87 2329.68 2.87
## 2 Austria 12.07 23.32 4.41 1507.99 3.93
## 3 Belgium 13.17 23.80 4.43 2108.47 3.82
## 4 Bolivia 5.75 41.89 1.67 189.13 0.22
## 5 Brazil 12.88 42.19 0.83 728.47 4.56
## 6 Canada 8.79 31.72 2.85 2982.88 2.43
## 7 Chile 0.60 39.74 1.34 662.86 2.67
## 8 China 11.90 44.75 0.67 289.52 6.51
## 9 Colombia 4.98 46.64 1.06 276.65 3.08
## 10 Costa Rica 10.78 47.64 1.14 471.24 2.80
## 11 Denmark 16.85 24.42 3.93 2496.53 3.99
## 12 Ecuador 3.59 46.31 1.19 287.77 2.19
## 13 Finland 11.24 27.84 2.37 1681.25 4.32
## 14 France 12.64 25.06 4.70 2213.82 4.52
## 15 Germany 12.55 23.31 3.35 2457.12 3.44
## 16 Greece 10.67 25.62 3.10 870.85 6.28
## 17 Guatamala 3.01 46.05 0.87 289.71 1.48
## 18 Honduras 7.70 47.32 0.58 232.44 3.19
## 19 Iceland 1.27 34.03 3.08 1900.10 1.12
## 20 India 9.00 41.31 0.96 88.94 1.54
## 21 Ireland 11.34 31.16 4.19 1139.95 2.99
## 22 Italy 14.28 24.52 3.48 1390.00 3.54
## 23 Japan 21.10 27.01 1.91 1257.28 8.21
## 24 Korea 3.98 41.74 0.91 207.68 5.81
## 25 Luxembourg 10.35 21.80 3.73 2449.39 1.57
## 26 Malta 15.48 32.54 2.47 601.05 8.12
## 27 Norway 10.25 25.95 3.67 2231.03 3.62
## 28 Netherlands 14.65 24.71 3.25 1740.70 7.66
## 29 New Zealand 10.67 32.61 3.17 1487.52 1.76
## 30 Nicaragua 7.30 45.04 1.21 325.54 2.48
## 31 Panama 4.44 43.56 1.20 568.56 3.61
## 32 Paraguay 2.02 41.18 1.05 220.56 1.03
## 33 Peru 12.70 44.19 1.28 400.06 0.67
## 34 Philippines 12.78 46.26 1.12 152.01 2.00
## 35 Portugal 12.49 28.96 2.85 579.51 7.48
## 36 South Africa 11.14 31.94 2.28 651.11 2.19
## 37 South Rhodesia 13.30 31.92 1.52 250.96 2.00
## 38 Spain 11.77 27.74 2.87 768.79 4.35
## 39 Sweden 6.86 21.44 4.54 3299.49 3.01
## 40 Switzerland 14.13 23.49 3.73 2630.96 2.70
## 41 Turkey 5.13 43.42 1.08 389.66 2.96
## 42 Tunisia 2.81 46.12 1.21 249.87 1.13
## 43 United Kingdom 7.81 23.27 4.46 1813.93 2.01
## 44 United States 7.56 29.81 3.43 4001.89 2.45
## 45 Venezuela 9.22 46.40 0.90 813.39 0.53
## 46 Zambia 18.56 45.25 0.56 138.33 5.14
## 47 Jamaica 7.72 41.12 1.73 380.47 10.23
## 48 Uruguay 9.24 28.13 2.72 766.54 1.88
## 49 Libya 8.89 43.69 2.07 123.58 16.71
## 50 Malaysia 4.71 47.20 0.66 242.69 5.08
LifeCycleSavings <- data.frame(LifeCycleSavings)
summary(LifeCycleSavings)
## X sr pop15 pop75
## Australia: 1 Min. : 0.600 Min. :21.44 Min. :0.560
## Austria : 1 1st Qu.: 6.970 1st Qu.:26.21 1st Qu.:1.125
## Belgium : 1 Median :10.510 Median :32.58 Median :2.175
## Bolivia : 1 Mean : 9.671 Mean :35.09 Mean :2.293
## Brazil : 1 3rd Qu.:12.617 3rd Qu.:44.06 3rd Qu.:3.325
## Canada : 1 Max. :21.100 Max. :47.64 Max. :4.700
## (Other) :44
## dpi ddpi
## Min. : 88.94 Min. : 0.220
## 1st Qu.: 288.21 1st Qu.: 2.002
## Median : 695.66 Median : 3.000
## Mean :1106.76 Mean : 3.758
## 3rd Qu.:1795.62 3rd Qu.: 4.478
## Max. :4001.89 Max. :16.710
##
median(LifeCycleSavings$sr)
## [1] 10.51
mean(LifeCycleSavings$sr)
## [1] 9.671
median(LifeCycleSavings$pop15)
## [1] 32.575
mean(LifeCycleSavings$pop15)
## [1] 35.0896
# 2. Make Subset
LifeCycleSubset <- data.frame(subset(LifeCycleSavings, sr >= 5 & pop15 >= 30, select = c(X,sr, pop15, pop75, dpi, ddpi)))
LifeCycleSubset
## X sr pop15 pop75 dpi ddpi
## 4 Bolivia 5.75 41.89 1.67 189.13 0.22
## 5 Brazil 12.88 42.19 0.83 728.47 4.56
## 6 Canada 8.79 31.72 2.85 2982.88 2.43
## 8 China 11.90 44.75 0.67 289.52 6.51
## 10 Costa Rica 10.78 47.64 1.14 471.24 2.80
## 18 Honduras 7.70 47.32 0.58 232.44 3.19
## 20 India 9.00 41.31 0.96 88.94 1.54
## 21 Ireland 11.34 31.16 4.19 1139.95 2.99
## 26 Malta 15.48 32.54 2.47 601.05 8.12
## 29 New Zealand 10.67 32.61 3.17 1487.52 1.76
## 30 Nicaragua 7.30 45.04 1.21 325.54 2.48
## 33 Peru 12.70 44.19 1.28 400.06 0.67
## 34 Philippines 12.78 46.26 1.12 152.01 2.00
## 36 South Africa 11.14 31.94 2.28 651.11 2.19
## 37 South Rhodesia 13.30 31.92 1.52 250.96 2.00
## 41 Turkey 5.13 43.42 1.08 389.66 2.96
## 45 Venezuela 9.22 46.40 0.90 813.39 0.53
## 46 Zambia 18.56 45.25 0.56 138.33 5.14
## 47 Jamaica 7.72 41.12 1.73 380.47 10.23
## 49 Libya 8.89 43.69 2.07 123.58 16.71
# 3. Rename Subset columns
LifeCycleSubset <- setNames(LifeCycleSubset, c("Country","Savings Ratio", "Per Pop under 15", "Per Pop over 75", "Disposable Inc","Growth Rate of DPI"))
LifeCycleSubset
## Country Savings Ratio Per Pop under 15 Per Pop over 75
## 4 Bolivia 5.75 41.89 1.67
## 5 Brazil 12.88 42.19 0.83
## 6 Canada 8.79 31.72 2.85
## 8 China 11.90 44.75 0.67
## 10 Costa Rica 10.78 47.64 1.14
## 18 Honduras 7.70 47.32 0.58
## 20 India 9.00 41.31 0.96
## 21 Ireland 11.34 31.16 4.19
## 26 Malta 15.48 32.54 2.47
## 29 New Zealand 10.67 32.61 3.17
## 30 Nicaragua 7.30 45.04 1.21
## 33 Peru 12.70 44.19 1.28
## 34 Philippines 12.78 46.26 1.12
## 36 South Africa 11.14 31.94 2.28
## 37 South Rhodesia 13.30 31.92 1.52
## 41 Turkey 5.13 43.42 1.08
## 45 Venezuela 9.22 46.40 0.90
## 46 Zambia 18.56 45.25 0.56
## 47 Jamaica 7.72 41.12 1.73
## 49 Libya 8.89 43.69 2.07
## Disposable Inc Growth Rate of DPI
## 4 189.13 0.22
## 5 728.47 4.56
## 6 2982.88 2.43
## 8 289.52 6.51
## 10 471.24 2.80
## 18 232.44 3.19
## 20 88.94 1.54
## 21 1139.95 2.99
## 26 601.05 8.12
## 29 1487.52 1.76
## 30 325.54 2.48
## 33 400.06 0.67
## 34 152.01 2.00
## 36 651.11 2.19
## 37 250.96 2.00
## 41 389.66 2.96
## 45 813.39 0.53
## 46 138.33 5.14
## 47 380.47 10.23
## 49 123.58 16.71
# 4. Get overview and mean and median of same attributes. Compare the results
summary(LifeCycleSubset)
## Country Savings Ratio Per Pop under 15 Per Pop over 75
## Bolivia : 1 Min. : 5.130 Min. :31.16 Min. :0.560
## Brazil : 1 1st Qu.: 8.523 1st Qu.:32.59 1st Qu.:0.945
## Canada : 1 Median :10.725 Median :42.80 Median :1.245
## China : 1 Mean :10.552 Mean :40.62 Mean :1.614
## Costa Rica: 1 3rd Qu.:12.720 3rd Qu.:45.09 3rd Qu.:2.123
## Honduras : 1 Max. :18.560 Max. :47.64 Max. :4.190
## (Other) :14
## Disposable Inc Growth Rate of DPI
## Min. : 88.94 Min. : 0.220
## 1st Qu.: 221.61 1st Qu.: 1.940
## Median : 385.06 Median : 2.640
## Mean : 591.81 Mean : 3.951
## 3rd Qu.: 670.45 3rd Qu.: 4.705
## Max. :2982.88 Max. :16.710
##
median(LifeCycleSubset$"Savings Ratio")
## [1] 10.725
mean(LifeCycleSubset$"Savings Ratio")
## [1] 10.5515
median(LifeCycleSubset$"Per Pop under 15")
## [1] 42.805
mean(LifeCycleSubset$"Per Pop under 15")
## [1] 40.618
The mean and median of the savings ratio and percent population over 15 both increase for the subset where the savings ratio is greater than or equal to 5 and the percent population under 15 is greater than or equal to 30.
# 5.
LifeCycleSavings$dpi[LifeCycleSavings$dpi >= 2500 & LifeCycleSavings$dpi < 3000] <- 3000
LifeCycleSavings$ddpi[LifeCycleSavings$ddpi >= 3 & LifeCycleSavings$ddpi < 4] <- 4
LifeCycleSavings$sr[LifeCycleSavings$sr >= 18] <- 20
LifeCycleSavings
## X sr pop15 pop75 dpi ddpi
## 1 Australia 11.43 29.35 2.87 2329.68 2.87
## 2 Austria 12.07 23.32 4.41 1507.99 4.00
## 3 Belgium 13.17 23.80 4.43 2108.47 4.00
## 4 Bolivia 5.75 41.89 1.67 189.13 0.22
## 5 Brazil 12.88 42.19 0.83 728.47 4.56
## 6 Canada 8.79 31.72 2.85 3000.00 2.43
## 7 Chile 0.60 39.74 1.34 662.86 2.67
## 8 China 11.90 44.75 0.67 289.52 6.51
## 9 Colombia 4.98 46.64 1.06 276.65 4.00
## 10 Costa Rica 10.78 47.64 1.14 471.24 2.80
## 11 Denmark 16.85 24.42 3.93 2496.53 4.00
## 12 Ecuador 3.59 46.31 1.19 287.77 2.19
## 13 Finland 11.24 27.84 2.37 1681.25 4.32
## 14 France 12.64 25.06 4.70 2213.82 4.52
## 15 Germany 12.55 23.31 3.35 2457.12 4.00
## 16 Greece 10.67 25.62 3.10 870.85 6.28
## 17 Guatamala 3.01 46.05 0.87 289.71 1.48
## 18 Honduras 7.70 47.32 0.58 232.44 4.00
## 19 Iceland 1.27 34.03 3.08 1900.10 1.12
## 20 India 9.00 41.31 0.96 88.94 1.54
## 21 Ireland 11.34 31.16 4.19 1139.95 2.99
## 22 Italy 14.28 24.52 3.48 1390.00 4.00
## 23 Japan 20.00 27.01 1.91 1257.28 8.21
## 24 Korea 3.98 41.74 0.91 207.68 5.81
## 25 Luxembourg 10.35 21.80 3.73 2449.39 1.57
## 26 Malta 15.48 32.54 2.47 601.05 8.12
## 27 Norway 10.25 25.95 3.67 2231.03 4.00
## 28 Netherlands 14.65 24.71 3.25 1740.70 7.66
## 29 New Zealand 10.67 32.61 3.17 1487.52 1.76
## 30 Nicaragua 7.30 45.04 1.21 325.54 2.48
## 31 Panama 4.44 43.56 1.20 568.56 4.00
## 32 Paraguay 2.02 41.18 1.05 220.56 1.03
## 33 Peru 12.70 44.19 1.28 400.06 0.67
## 34 Philippines 12.78 46.26 1.12 152.01 2.00
## 35 Portugal 12.49 28.96 2.85 579.51 7.48
## 36 South Africa 11.14 31.94 2.28 651.11 2.19
## 37 South Rhodesia 13.30 31.92 1.52 250.96 2.00
## 38 Spain 11.77 27.74 2.87 768.79 4.35
## 39 Sweden 6.86 21.44 4.54 3299.49 4.00
## 40 Switzerland 14.13 23.49 3.73 3000.00 2.70
## 41 Turkey 5.13 43.42 1.08 389.66 2.96
## 42 Tunisia 2.81 46.12 1.21 249.87 1.13
## 43 United Kingdom 7.81 23.27 4.46 1813.93 2.01
## 44 United States 7.56 29.81 3.43 4001.89 2.45
## 45 Venezuela 9.22 46.40 0.90 813.39 0.53
## 46 Zambia 20.00 45.25 0.56 138.33 5.14
## 47 Jamaica 7.72 41.12 1.73 380.47 10.23
## 48 Uruguay 9.24 28.13 2.72 766.54 1.88
## 49 Libya 8.89 43.69 2.07 123.58 16.71
## 50 Malaysia 4.71 47.20 0.66 242.69 5.08
# 6.Display enough rows.
# See above
# 7. Load file using Git
LifeCycleSavings2 <- read.csv(url("https://raw.githubusercontent.com/dquarshie89/R-Bridge/master/LifeCycleSavings.csv"),header = TRUE)
LifeCycleSavings2
## X sr pop15 pop75 dpi ddpi
## 1 Australia 11.43 29.35 2.87 2329.68 2.87
## 2 Austria 12.07 23.32 4.41 1507.99 3.93
## 3 Belgium 13.17 23.80 4.43 2108.47 3.82
## 4 Bolivia 5.75 41.89 1.67 189.13 0.22
## 5 Brazil 12.88 42.19 0.83 728.47 4.56
## 6 Canada 8.79 31.72 2.85 2982.88 2.43
## 7 Chile 0.60 39.74 1.34 662.86 2.67
## 8 China 11.90 44.75 0.67 289.52 6.51
## 9 Colombia 4.98 46.64 1.06 276.65 3.08
## 10 Costa Rica 10.78 47.64 1.14 471.24 2.80
## 11 Denmark 16.85 24.42 3.93 2496.53 3.99
## 12 Ecuador 3.59 46.31 1.19 287.77 2.19
## 13 Finland 11.24 27.84 2.37 1681.25 4.32
## 14 France 12.64 25.06 4.70 2213.82 4.52
## 15 Germany 12.55 23.31 3.35 2457.12 3.44
## 16 Greece 10.67 25.62 3.10 870.85 6.28
## 17 Guatamala 3.01 46.05 0.87 289.71 1.48
## 18 Honduras 7.70 47.32 0.58 232.44 3.19
## 19 Iceland 1.27 34.03 3.08 1900.10 1.12
## 20 India 9.00 41.31 0.96 88.94 1.54
## 21 Ireland 11.34 31.16 4.19 1139.95 2.99
## 22 Italy 14.28 24.52 3.48 1390.00 3.54
## 23 Japan 21.10 27.01 1.91 1257.28 8.21
## 24 Korea 3.98 41.74 0.91 207.68 5.81
## 25 Luxembourg 10.35 21.80 3.73 2449.39 1.57
## 26 Malta 15.48 32.54 2.47 601.05 8.12
## 27 Norway 10.25 25.95 3.67 2231.03 3.62
## 28 Netherlands 14.65 24.71 3.25 1740.70 7.66
## 29 New Zealand 10.67 32.61 3.17 1487.52 1.76
## 30 Nicaragua 7.30 45.04 1.21 325.54 2.48
## 31 Panama 4.44 43.56 1.20 568.56 3.61
## 32 Paraguay 2.02 41.18 1.05 220.56 1.03
## 33 Peru 12.70 44.19 1.28 400.06 0.67
## 34 Philippines 12.78 46.26 1.12 152.01 2.00
## 35 Portugal 12.49 28.96 2.85 579.51 7.48
## 36 South Africa 11.14 31.94 2.28 651.11 2.19
## 37 South Rhodesia 13.30 31.92 1.52 250.96 2.00
## 38 Spain 11.77 27.74 2.87 768.79 4.35
## 39 Sweden 6.86 21.44 4.54 3299.49 3.01
## 40 Switzerland 14.13 23.49 3.73 2630.96 2.70
## 41 Turkey 5.13 43.42 1.08 389.66 2.96
## 42 Tunisia 2.81 46.12 1.21 249.87 1.13
## 43 United Kingdom 7.81 23.27 4.46 1813.93 2.01
## 44 United States 7.56 29.81 3.43 4001.89 2.45
## 45 Venezuela 9.22 46.40 0.90 813.39 0.53
## 46 Zambia 18.56 45.25 0.56 138.33 5.14
## 47 Jamaica 7.72 41.12 1.73 380.47 10.23
## 48 Uruguay 9.24 28.13 2.72 766.54 1.88
## 49 Libya 8.89 43.69 2.07 123.58 16.71
## 50 Malaysia 4.71 47.20 0.66 242.69 5.08