Browsing resource, all submissions are temporary.
This problem requires you to run your code you have written for the programming exercise. Read this instruction first before attempting the questions.
To run your code, type source("filename of your code"). If you follow the template to build the code, there should be 69 columns in your data frame hw after the code is executed. Columns 46-67 are the HW scores in percentages. Column 68 is the HW percent average after dropping the lowest 2 HW percents. Column 69 is the Bonus HW points. If you are not using the template, make sure to follow the rounding instruction stated in the requirements of the programming exercise on the instruction page.
hw
a. (6 points) Fill in the blanks in the table below. (You could look at your csv file if you think it's easier)
b. (1 point) What is the class average of the HW score percentage for "Wed HW 8"? Round your answer to 2 decimal places.
(Hint: "Wed HW 8" percent scores should be in column 60 of the data frame. Type names(hw)[60] to confirm it.)
names(hw)[60]
Now that you have tried your code on the data set you've worked on. It's time to test your code on a new data set. This is another fake data set in which the scores are assigned according to a formula.
The following R code generates 5 HW scores and outputs them to a csv file named 'HW_scores_for_code_validation.csv'. For the purpose of this exercise, you don't need to know exactly what the code is doing. Copy and paste the code to your R console to run it.
### Generate fake HW scores for code validation rm(list=ls()) # clear working space outputfile <- 'HW_scores_for_code_validation.csv' nstd <- 50 # number of students n_hw <- 5 # number of HW # create data frame hw with username set to student001, student002, ... hw <- data.frame(username=sprintf('student%03d',1:nstd)) hw[,2:(2*n_hw+1)] <- NA # initialize other columns to NA # Set column names names(hw)[1] <- "username" for (i in 1:n_hw) { names(hw)[2*i] <- paste('HW',i) names(hw)[2*i+1] <- paste('HW',i,'max score') } # set max HW scores randomly between 10 and 100 RNGversion("3.5.0") set.seed(980918) max_scores <- sample(10:100,n_hw) # Assign HW scores to students according to a formula fmax <- (1:n_hw)/n_hw for (i in 1:nstd) { hw[i,seq(3,2*n_hw+1,2)] <- max_scores hw[i,seq(2,2*n_hw,2)] <- sample(fmax) * max_scores } j <- 2*sample.int(n_hw,3) hw[seq(1,nstd,2),j] <- hw[seq(1,nstd,2),j]*(1 - (n_hw*(n_hw-1)-19)/2) # Output to csv file write.csv(hw, outputfile, row.names=FALSE)
Take a look at the 'HW_scores_for_code_validation.csv' file generated by the code. Note that even though there are now 5 HW sets, your code should still be able to handle it since the number of HW sets in your code is not hardwired to 22. Go to your code file and change the 'inputfile' parameter to 'HW_scores_for_code_validation.csv'. You can change the 'outputfile' parameter to something else if you want. Run your code and look at the output csv file. Answer the following questions.
c. (1 point) Are the HW % average (after dropping lowest 2 HW percents) and Bonus HW points exactly the same for all students? yes no
d. (6 points) What are the HW average and Bonus HW points for the 10th student (username = student010)?
HW % average (after dropping lowest 2) =
Bonus HW points =