##CHAPTER 2.7 Practice Problems

## Soal 1
Movie <- c("Citizen Kane", "The Godfather", "Casablanca", "Raging Bull", "Singing in the Rain")

## Soal 2
Year <- c(1941, 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)


## Soal 6
Title <- c("The Secret of Monkey Island", 
           "Indiana Jones and the Fate of Atlantis", 
           "Day of the Tentacle", 
           "Grim Fandango")

## Soal 7
Release <- c(1990, 1992, 1993, 1998)

## Soal 8
Lucasartfounding_year <- 1982

## Soal 9
Rank <- c(14, 11, 6, 1)

## Soal 10
Tittle <- data.frame(Title, Release, Rank)
Tittle
##                                    Title Release Rank
## 1            The Secret of Monkey Island    1990   14
## 2 Indiana Jones and the Fate of Atlantis    1992   11
## 3                    Day of the Tentacle    1993    6
## 4                          Grim Fandango    1998    1

##CHAPTER 4 ## 4.2

hours=c(8.84, 3.26, 2.81, 0.64, 0.60, 
        0.53, 0.37, 0.35, 0.31, 0.24)
hours[c(2,4,6)]
## [1] 3.26 0.64 0.53
hours[hours>1]
## [1] 8.84 3.26 2.81
hours[hours>=0.5&hours<=0.75]
## [1] 0.64 0.60 0.53
hours[hours<0.25|hours>4]
## [1] 8.84 0.24
## 4.3
data <- data.frame
Name = c("Sleeping", "Working", "Watching Television", "Socializing", "Food   
          Preparation", "Housework", 
          "Childcare",  "Consumer Goods   
          Purchase", "Participating in 
          Recreation", "Attending Class")
AverageHours = c(8.84, 3.26, 2.81, 0.64, 
                 0.60, 0.53, 0.37, 0.35, 
                 0.31, 0.24)
Category = c("Personal Care",
             "Work-Related", "Leisure", 
             "Leisure", "Household", 
             "Household", "Caring for 
             Household", "Purchasing", 
             "Leisure", "Education")
data <- data.frame(Name, AverageHours, Category)
data
##                                       Name AverageHours
## 1                                 Sleeping         8.84
## 2                                  Working         3.26
## 3                      Watching Television         2.81
## 4                              Socializing         0.64
## 5           Food   \n          Preparation         0.60
## 6                                Housework         0.53
## 7                                Childcare         0.37
## 8    Consumer Goods   \n          Purchase         0.35
## 9  Participating in \n          Recreation         0.31
## 10                         Attending Class         0.24
##                               Category
## 1                        Personal Care
## 2                         Work-Related
## 3                              Leisure
## 4                              Leisure
## 5                            Household
## 6                            Household
## 7  Caring for \n             Household
## 8                           Purchasing
## 9                              Leisure
## 10                           Education

4.4

set.seed(8)
rnorm(10)
##  [1] -0.08458607  0.84040013 -0.46348277 -0.55083500  0.73604043 -0.10788140
##  [7] -0.17028915 -1.08833171 -3.01105168 -0.59317433

4.5

n <- 100
size <- 10
random_sample <- sample.int(n = n, size = size)
random_sample
##  [1] 68  9 76 62  7 40 19 63 70 96

4.6

help(sample.int)
## starting httpd help server ... done

Pratice Problem 4.7

## Soal 1
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, 322868, 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)


## Soal 2
selected_median_salaries <- Colleges$MedianSalary[Colleges$TopSalary > 400000]
print(selected_median_salaries)
## [1] 56496 63029 53080 54416 53045 60048 55000 51656
## Soal 3
selected_colleges <- Colleges[Colleges$Employees <= 1000, ]
print(selected_colleges)
##                        College Employees TopSalary MedianSalary
## 2          Christopher Newport       922    381486        47895
## 5                     Longwood       746    322868        52000
## 6                Norfolk State       919    295000        49605
## 9              Mary Washington       721    449865        53045
## 12 Virginia Military Institute       550    364269        44999
## 14              Virginia State       761    356524        55925
## Soal 4
sampled_colleges <- Colleges[sample(1:nrow(Colleges), size = 5), ]
print(sampled_colleges)
##          College Employees TopSalary MedianSalary
## 8        Radford      1273    312080        51000
## 5       Longwood       746    322868        52000
## 10      Virginia      7431    561099        60048
## 6  Norfolk State       919    295000        49605
## 13 Virginia Tech      7303    500000        51656