Chapter 2 : 2.7 Practice Problems

Soal 1

Movie=c("Citizen Kane", "The Godfather", "Casablanca", "Raging Bull", "Singing in The Rain")

Soal 2

Year=c(1951, 1972, 1942, 1980, 1952)

Soal 3

RunTime=c(119, 177, 102, 129, 103)

Soal 4

RunTimeHours=RunTime/60

Soal 5

MovieInfo=data.frame(Movie, Year, RunTime)
print(MovieInfo)
##                 Movie Year RunTime
## 1        Citizen Kane 1951     119
## 2       The Godfather 1972     177
## 3          Casablanca 1942     102
## 4         Raging Bull 1980     129
## 5 Singing in The Rain 1952     103

Soal 6

Title=c("The Secret Monkey Island", "Indiana Jones and The Fate of The Atlantis", "Day of The Tentacle", "Grim Fandango")

Soal 7

Release=c(1990, 1992, 1993, 1998)

Soal 8

Founded=1982
x=Release-Founded

Soal 9

Rank=c(14, 11, 6, 1)

Soal 10

AdventureGames=data.frame(Title, Release, Rank)
print(AdventureGames)
##                                        Title Release Rank
## 1                   The Secret Monkey Island    1990   14
## 2 Indiana Jones and The Fate of The Atlantis    1992   11
## 3                        Day of The Tentacle    1993    6
## 4                              Grim Fandango    1998    1

Chapter 4 : 4.7 Practice Problems

Membuat Data Frame “Colleges”

College=c("William and Mary", "Christopher Newport", "George Mason", "James Madison", "Longwood", "Norfolk State", "Old Dominion", "Radford", "Mary Washington", "Virginia", "Virginia Commonwealth", "Virginia Military Institute", "Virginia Tech", "Virginia State")
Employees=c(2104, 922, 4043, 2833, 746, 919, 2369, 1273, 721, 7431, 5825,550, 7303, 761)
TopSalary=c( 425000, 381486, 536714, 428400, 328268, 295000, 448272, 312080, 449865, 561099, 503154, 364269, 500000, 356524)
MedianSalary=c(56496, 47895, 63029, 53080, 52000, 49605, 54416, 51000, 53045, 60048, 55000, 44999, 51656, 55925)
Colleges=data.frame(College, Employees, TopSalary, MedianSalary)
print(Colleges)
##                        College Employees TopSalary MedianSalary
## 1             William and Mary      2104    425000        56496
## 2          Christopher Newport       922    381486        47895
## 3                 George Mason      4043    536714        63029
## 4                James Madison      2833    428400        53080
## 5                     Longwood       746    328268        52000
## 6                Norfolk State       919    295000        49605
## 7                 Old Dominion      2369    448272        54416
## 8                      Radford      1273    312080        51000
## 9              Mary Washington       721    449865        53045
## 10                    Virginia      7431    561099        60048
## 11       Virginia Commonwealth      5825    503154        55000
## 12 Virginia Military Institute       550    364269        44999
## 13               Virginia Tech      7303    500000        51656
## 14              Virginia State       761    356524        55925

Soal 1

TopSalaryX=Colleges$TopSalary[c(1, 3, 10, 12)]

Soal 2

MedianSalaryX=Colleges$MedianSalary[Colleges$TopSalary>400000]

Soal 3

EmployeesX=Colleges$Employees<=1000

Soal 4

SampleColleges=Colleges[sample.int(n=14, size=5), ]

Membuat Data Frame “Countries”

Nation=c("China", "India", "United States", "Indonesia", "Brazil", "Pakistan", "Nigeria", "Bangladesh", "Russia", "Mexico")
Region=c("Asia", "Asia", "North America", "Asia", "South America", "Asia", "Africa", "Asia", "Europe", "North America")
Population=c(1409517397, 1339180127, 324459463, 263991379, 209288278, 197015955, 190886311, 164669751, 143989754, 129163276)
PctIncrease = c(0.40, 1.10, 0.70, 1.10, 0.80, 2.00, 2.60, 1.10, 0.00, 1.30)
GDPcapita = c(8582, 1852, 57467, 3895, 10309, 1629, 2640, 1524, 10248, 8562)
Countries=data.frame(Nation, Region, Population, PctIncrease, GDPcapita)
print(Countries)
##           Nation        Region Population PctIncrease GDPcapita
## 1          China          Asia 1409517397         0.4      8582
## 2          India          Asia 1339180127         1.1      1852
## 3  United States North America  324459463         0.7     57467
## 4      Indonesia          Asia  263991379         1.1      3895
## 5         Brazil South America  209288278         0.8     10309
## 6       Pakistan          Asia  197015955         2.0      1629
## 7        Nigeria        Africa  190886311         2.6      2640
## 8     Bangladesh          Asia  164669751         1.1      1524
## 9         Russia        Europe  143989754         0.0     10248
## 10        Mexico North America  129163276         1.3      8562

Soal 5

GDPcapitaX=Countries[Countries$PctIncrease<10000, ]
GDPcapitaX=Countries[Countries$Region!="Asia", ]

Soal 6

SampleNation=Nation[sample.int(n=10, size=3)]

Soal 7

PctIncreaseX=Nation[Countries$PctIncrease>1.5]

Membuat Data Frame “Olympics”

YearOlym=c(1992, 1992, 1994, 1996, 1998, 2000, 2002, 2004, 2006, 2008, 2010, 2012, 2014, 2016, 2018)
Type=c("Summer", "Winter", "Winter", "Summer", "Winter", "Summer", "Winter", "Summer", "Winter", "Summer", "Winter", "Summer", "Winter", "Summer", "Winter")
Host=c("Spain", "France", "Norway", "United States", "Japan", "Australia", "United States", "Greece", "Italy", "China", "Canada", "United Kingdom", "Russia", "Brazil", "South Korea")
Competitors=c(9356, 1801, 1737, 10318, 2176, 10651, 2399, 10625, 2508, 10942, 2566, 10768, 2873, 11238, 2922)
Events=c(257, 57, 61, 271, 68, 300, 78, 301, 84, 302, 86, 302, 98, 306, 102)
Nations=c(169, 64, 67, 197, 72, 199, 78, 201, 80, 204, 82, 204, 88, 207, 92)
Leader=c("Unified Team", "Germany", "Russia", "United States", "Germany", "United States", "Norway", "United States", "Germany", "China", "Canada", "United States", "Russia", "United States", "Norway")
Olympics=data.frame(YearOlym, Type, Host, Competitors, Events, Nations, Leader)
print(Olympics)
##    YearOlym   Type           Host Competitors Events Nations        Leader
## 1      1992 Summer          Spain        9356    257     169  Unified Team
## 2      1992 Winter         France        1801     57      64       Germany
## 3      1994 Winter         Norway        1737     61      67        Russia
## 4      1996 Summer  United States       10318    271     197 United States
## 5      1998 Winter          Japan        2176     68      72       Germany
## 6      2000 Summer      Australia       10651    300     199 United States
## 7      2002 Winter  United States        2399     78      78        Norway
## 8      2004 Summer         Greece       10625    301     201 United States
## 9      2006 Winter          Italy        2508     84      80       Germany
## 10     2008 Summer          China       10942    302     204         China
## 11     2010 Winter         Canada        2566     86      82        Canada
## 12     2012 Summer United Kingdom       10768    302     204 United States
## 13     2014 Winter         Russia        2873     98      88        Russia
## 14     2016 Summer         Brazil       11238    306     207 United States
## 15     2018 Winter    South Korea        2922    102      92        Norway

Soal 8

OlympicsLeader=Olympics[Olympics$Host == Olympics$Leader, ]

Soal 9

CompetitorsPerEvent=Olympics[Olympics$Competitors/Olympics$Events>35, ]

Soal 10

WinterNations=Olympics[Olympics$Type =="Winter"&Olympics$Nations>=80, ]