1 Assignment 1: Base R Foundations
R as a Calculator • Vectors • Data Frames • Built-in Datasets
2 Overview
This assignment introduces core concepts in base R, including arithmetic operations, object assignment, vectors, data frames, and built-in datasets. The goal is to build comfort with fundamental R syntax before moving into more advanced workflows.
You will complete all tasks in a single .R script.
3 Learning Objectives
By completing this assignment, you will be able to:
- Perform arithmetic operations in R
- Assign results to objects using
<- - Create and manipulate vectors
- Construct and subset data frames
- Explore built-in datasets
- Produce a simple base R visualization
- Organize a script using clear comments
4 Textbook Connection
This assignment builds directly from Chapter 1: Introduction to R in Reproducible Research Using R.
Students are encouraged to review the chapter before beginning this assignment, as it provides the conceptual foundation and reproducible workflow demonstrated here.
5 Submission Instructions
Submit one .R script file.
Your script must:
- Be clearly organized into labeled sections
(e.g.,# Part 1: R as a Calculator) - Include all required calculations and outputs
- Include your reflection as comments at the end
- Run from top to bottom without errors
6 Assignment Tasks
6.1 1. R as a Calculator
- Calculate
12 * 2. - Calculate the square root of
144. - Calculate
100 / 7and round to 2 decimals. - Save the result of
15 * 4asmy_product. - Save
100 / 7, rounded to 5 decimals, asmy_second_product.
6.2 2. Vectors
- Create a numeric vector of five random numbers named
randy. - Compute the mean, median, minimum, and maximum of
randy. - Create another numeric vector of five random numbers named
randy2. - Create
randy_combinedby addingrandyandrandy2. - Create a character vector of five favorite movies.
- Use indexing to print the fourth movie.
- Create a factor with 11 entries of favorite foods (repeat some).
- Use
table()to count frequencies. - Sort the table in descending order and save as
organized_table.
6.3 3. Data Frames
- Create a data frame called
class_dfwith columns:- name
- age
- major
- name
- Add at least four fictional classmates.
- Create
age_in_2009. - Create
favorite_professor. - Use indexing to:
- Select only name and major.
- Filter rows for Psych majors.
6.4 4. Built-in Datasets
Using mtcars:
- Display the first 11 rows.
- List all column names.
- Run
str(mtcars)and describe column types in a comment. - Run
summary(mtcars). - Create a base R scatterplot titled:
“My First Scatterplot”
6.5 Reflection
At the end of your script, answer in 2–3 sentences (as comments):
What was the most surprising or confusing thing you learned about R so far?
7 Reproducibility Practice
For this first assignment, focus on script organization and documentation.
At the top of your script, include a structured comment block containing:
- Assignment name
- Your name
- Date
- A brief description of what the script accomplishes
Your script should:
- Be divided into clearly labeled sections
- Run from top to bottom without manual intervention
- Avoid unnecessary objects
This assignment establishes your baseline reproducibility habits for the semester.