- Assigned: Thursday, 17th September 2026 at 2:30pm
- Due: Thursday, 24th September 2026 at 11:59pm
- Expiration: Thursday, 1st October 2026 at 11:59pm
Note: the expiration date is the last date you can submit your work for a grade.
Some elements of this lab were written or corrected by Claud.
Welcome to Lab 02! This week, you will dig into the data structure that powers most of data science in R: the data frame. You will build data frames from scratch, load built-in R datasets, read in a real CSV file, run statistical summaries, and create visualizations โ all while fixing intentionally broken code along the way.
By the end of this lab, you will be able to:
- Create a data frame with
data.frame()and access its rows, columns, and subsets - Explore built-in R datasets (
mtcars,iris) usingstr(),summary(), andhead() - Read an external
.csvfile into R withread.csv() - Detect and handle missing data (
NA) using two different strategies - Compute descriptive statistics: mean, median, standard deviation, quantiles, and correlation
- Compute grouped summaries with
aggregate()andtapply() - Build visualizations with
plot(),hist(),boxplot(), andpairs() - Use a Shiny app to interactively build data frames and generate plots
You have one week to complete this lab. There are five R programs, each focused on one part of the data analysis workflow. Each program contains a working example built by your instructor โ but several lines have been intentionally broken! Your job is to find each bug, understand why it's wrong, and fix it using the hints provided.
After completing the five programs, you'll explore a fully working Shiny app that lets you build your own data frame and generate plots interactively โ no bugs to fix there, just explore and think critically about what you see.
-
Create a local working space: A local directory is used to keep all your labs together in the same spot on your local machine and will help you locate them for future use. Please note that these local repositories are located on your machine and will still need to be pushed to GitHub. The UNIX command to create a local directory
cs301Fall2026/labsis as follows (if you are using a Windows machine, you can create the directory using File Explorer or use Git Bash to run the command below):mkdir -p cs301Fall2026/labs
Keep all your labs together in this local directory. If you are working with an activity, create a similar local directory for your course activities.
- Clone this repository to your computer. Use the command:
git clone <your-repo-url>to clone the repository. - Open the lab folder as an RStudio Project: In RStudio, choose File โ Open Project and select this lab's folder. This makes sure your working directory is set correctly, so relative paths like
data/student_survey.csvwill work. - Open the
src/student/folder in RStudio and copy each program's code into a new R script (or work directly in a copy you create) โ this is your deliverable. - Look for
TODOandBUG/HINTcomments - these tell you exactly where to add code or fix a mistake. Please be sure to REMOVE theTODOcomments after you have completed each task. - Run each program to test your work, either line-by-line in the RStudio console or with
Rscript src/student/program1_creating_dataframes.Rfrom the terminal. - Explore the Shiny app in
src/shiny_app.Ronce you finish the five programs. - Fill out
writing/reflection.mdwhen you are done coding and exploring.
File: src/student/program1_creating_dataframes.R
What You will Learn: Building a data.frame(), inspecting it with str()/summary(), and accessing rows, columns, and subsets.
What It Does:
- Builds a small data frame of five students (name, age, major, GPA, honors status)
- Prints the structure and summary statistics of the data frame
- Accesses a single column, a single row, and a logical subset
- Adds a new computed column (
gpa_percent)
Bugs to fix: a mismatched vector length, an incorrectly capitalized column name, a missing comma in row indexing, = used instead of ==, and a typo in a column name.
Key Concepts: data.frame(), $ access, row/column indexing, logical subsetting, str(), summary()
File: src/student/program2_builtin_datasets.R
What You will Learn: Working with R's built-in practice datasets, mtcars and iris.
What It Does:
- Loads
mtcarsand previews it withhead()andstr() - Filters cars with good fuel economy
- Computes average horsepower
- Loads
irisand computes grouped averages and counts by species
Bugs to fix: a missing comma in row filtering, incorrectly capitalized column names in mtcars and iris.
Key Concepts: data(), head(), str(), row filtering, aggregate(), table()
File: src/student/program3_reading_csv.R
What You will Learn: Reading an external .csv file and handling missing data.
What It Does:
- Reads
data/student_survey.csv, a synthetic dataset of 28 students (major, study hours, sleep hours, coffee cups, exam score) - Counts missing values per column
- Drops rows with a missing
exam_score - Fills missing
study_hoursvalues with the column mean
Bugs to fix: an incorrect file path, a missing ! (NOT) when filtering out missing values, a missing na.rm = TRUE, and incomplete code to fill in missing values.
Key Concepts: read.csv(), is.na(), colSums(), dropping vs. imputing missing data
File: src/student/program4_statistical_analysis.R
What You will Learn: Descriptive statistics and grouped summaries.
What It Does:
- Computes mean, median, standard deviation, range, and quantiles of exam scores
- Computes the correlation between
study_hoursandexam_score - Computes average exam score and average study hours grouped by major
- Identifies students scoring above the class average
Bugs to fix: an invalid function name for standard deviation, a missing use = "complete.obs" in cor(), a missing na.rm = TRUE in tapply(), and incomplete code for the final filtering step.
Key Concepts: mean(), median(), sd(), quantile(), cor(), aggregate(), tapply()
File: src/student/program5_data_visualization.R
What You will Learn: Creating scatterplots, histograms, boxplots, and scatterplot matrices with base R.
What It Does:
- Creates a scatterplot of
study_hoursvs.exam_scorewith a trend line - Creates a histogram of exam scores
- Creates a boxplot of exam scores grouped by major
- Creates a scatterplot matrix of the
irismeasurements
Bugs to fix: reversed formula arguments in lm(), incomplete histogram code, a reversed formula in boxplot(), and an incorrect column range passed to pairs().
Key Concepts: plot(), abline(), lm(), hist(), boxplot(), pairs()
File: src/shiny_app.R
This app is provided complete โ there is nothing to fix! Open it in RStudio and click Run App, or run:
install.packages("shiny") # only needed once
shiny::runApp("src/shiny_app.R")The app lets you:
- Choose a built-in synthetic dataset (the student survey,
mtcars,iris, or a synthetic sales dataset) or type in your own X and Y values to build a custom data frame - Generate a scatterplot, histogram, or boxplot from your data
- Preview the underlying data frame in a table
Spend some time exploring different datasets, columns, and plot types before you answer the Shiny app critical thinking questions in your reflection.
- Work through each program in order - later programs assume you understand earlier concepts.
- Read the
BUGandHINTcomments carefully - they tell you exactly what's wrong and how to think about the fix. - Test your code frequently - run the program after each fix.
- Don't be afraid to experiment - try things in the RStudio console and see what happens.
- Ask for help if you are stuck - that's what learning is all about!
To run any program from the terminal (with the lab folder as your working directory):
Rscript src/student/program1_creating_dataframes.R
Rscript src/student/program2_builtin_datasets.R
Rscript src/student/program3_reading_csv.R
Rscript src/student/program4_statistical_analysis.R
Rscript src/student/program5_data_visualization.RYou can also run each script line-by-line in RStudio to see the results and plots as you go.
Once you've completed all five programs and explored the Shiny app, answer the questions in writing/reflection.md. These questions will help you think deeply about data frames, statistics, visualization choices, and the responsible use of interactive tools.
When you are ready to submit:
- Make sure all five programs run without errors and produce sensible output
- Complete the
writing/reflection.mdfile - Test each program one more time
- Commit and push your changes to GitHub
- Submit the link to your repository
As you are working on your lab, you are to commit and push regularly. The commands (in the bash terminal) are shown below. Note: You can also use your VSCode editor (or similar) to commit and push your work. After you have pushed your work to your repository, please visit the repository at the GitHub website (you may have to log-in using your browser) to verify that your files were correctly sent.
git add -A
git commit -m "Your notes about commit here"
git pushThe grade that a student receives on this assignment will have the following components.
-
GitHub Actions CI Build Status [up to 15%]:: For the lab repository associated with this assignment students will receive a checkmark grade if their last before-the-deadline build passes. This is only checking some baseline writing and commit requirements as well as correct running of the program. An additional reduction will given if the commit log shows a cluster of commits at the end clearly used just to pass this requirement. An addition reduction will also be given if there is no commit during lab work times. All other requirements are evaluated manually.
-
Mastery of Technical Writing [up to 50%]:: Students will also receive a checkmark grade when the responses to the writing questions presented in the
reflection.mdreveal a proficiency of both writing skills and technical knowledge. To receive a checkmark grade, the submitted writing should have correct spelling, grammar, and punctuation in addition to following the rules of Markdown and providing conceptually and technically accurate answers. -
Mastery of Technical Knowledge and Skills [up to 35%]: Students will receive a portion of their assignment grade when their program implementation reveals that they have mastered all of the technical knowledge and skills developed during the completion of this assignment. As a part of this grade, the instructor will assess aspects of the programming including, but not limited to, the completeness and the correctness of the program and the use of effective source code comments.
As a separate grade, students will be required to complete code reviews of labs with the instructor or a Technical Leader. During this session, the student will be asked to demonstrate their understanding of the code they have written, and to provide responses to questions concerning specific programming concepts used in their implementation. The topics for this week's lab are listed below.
- Demonstrate working code (no errors during execution).
- Demonstrate documentation in code.
- Demonstrate that the code is complete, according to the assignment specifications.
- Discussion of
data.frame()indexing, missing data handling, and the difference betweenaggregate()andtapply(). - Discussion of other commands and parts of code
For immediate feedback on submissions, we will be using Gator Grade to inform the of missing components in the submission. As you submit, you will notice that there is a thick red X that will change to a green check mark when all components have been included in the submission. You are encouraged to click on the red X to find a listing of the components to address.
You can check the baseline writing and commit requirements for this lab assignment by running department's assignment checking gatorgrade tool. To use gatorgrade, you first need to make sure you have Python3 installed (type python --version to check). If you do not have Python installed, please see:
- Setting Up Python on Windows
- Python 3 Installation and Setup Guide
- How to Install Python 3 and Set Up a Local Programming Environment on Windows 10
Then, if you have not done so already, you need to install gatorgrade:
- First, install
pipx - Then, install
gatorgradewithpipx install gatorgrade
Finally, you can run gatorgrade: gatorgrade --config config/gatorgrade.yml
If you are stuck:
- Read the
BUGandHINTcomments in the code - Review the class materials (especially the Data Structures slide deck)
- Try breaking the problem into smaller steps
- Ask a classmate, Technical Leaders or your instructor
- Extra resources for using markdown include;
- Extra resources for R and RStudio include;
Students who have questions about this project outside of the lab time are invited to ask them in the course's Discord channel or during instructor's or TL's office hours.

