Lab 08
Lab 08
Study a problem
Prepare the input
Loop through all input
Build an inner loop to solve the problem
Analyze the solution
Upload and submit your saved file to Blackboard
Bonus
2
Problem:
Analyze Student Scores
3
Population standard deviation
6
Code the Solution in RStudio
Open RStudio in your computer
Menu File > Open File
7
Template Code
8
Prepare the variables
Input the number of total courses
10
Input all the course scores
Variable i iterates for each
course
E.g. i = 1,2,3,4,5,6 when the
course number is 6
Want to input scores for the
course i
Sample input/output
11
Input all the course scores
Variable i iterates for each
course
E.g. i = 1,2,3,4,5,6 when the
course number is 6
Get input scores for the course i
Sample input/output
12
Sum all the course scores
Variable i iterates for each
course
E.g. i = 1,2,3,4,5,6 when the
course number is 6
13
Find the Best and Worst
Variable i iterates for each
course
E.g. i = 1,2,3,4,5,6 when the
course number is 6
Using if statement
If we get a larger score, update
the best
If we get a lower score, update the
worst
Replace the …
14
Calculate the mean and SD
Replace …
15
Whenever scan() is used,
Run the Program choose Source but not Run
Click Source
16
Try different inputs
Every time you “source”, you can type a different
input to get a different output!
17
Blackboard Submission
Click Submit
18
Academic Honesty and Declaration
Statement
You must read the University Guideline on Academic Honesty
(https://www.cuhk.edu.hk/policy/academichonesty/), and place the following declaration
statement (with your information filled in) at the end of your .R script file as comments
You should NOT share your file to others, regardless of your intention
Submitting the wrong file by “accident” will NOT be accepted as an excuse – so please
double-check which file you have submitted
# Declaration
23