--- title: "Homework 03" author: "yourname" #date: "`r format(Sys.time(), '%d %B, %Y')`" output: #word_document: # toc: yes # number_sections: yes html_document: toc: no #number_sections: yes code_folding: show #hide --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` **This homework is due by Thursday by 2:30pm.** For this homework, you will save the `R Markdown` (e.g., `.Rmd`) homework document and save it to your `/fods-exercises/report` project directory. Either rename it or save a copy of this file so that its name has the prefix `2024_Lastname_FirstInitial`. Full name example: `2024_cookg_HW_03.Rmd`. *Enter your name in the author YAML code above* # **Overview** Build all code in your exercises/homework project and not your team project. The goal of this homework is to make another step toward structuring files and writing code for your team project. You will focus on writing code as well as creating a mental model for breaking large tasks into smaller pieces that are utilized for a bigger project. The content provided here should serve as a guideline for tackling other coding subtasks. You will create a data-cleaning script, load libraries, source external function scripts, import the raw data, view data frames, perform some cleaning techniques, export your data frame and source your scripts for this R Markdown report file which will include some in-line R objects. # **Step 1: Creating Initial Cleaning Script File** 1. Create a `.R` script file named: "champ_all_waves_initial_clean.R". 2. Save in `/r`. 3. Inside "champ_all_waves_initial_clean.R", add the content from this code block. Keep in mind that you cannot insert R Markdown code in `.R` scripts. You can use only `R` code. Notice the subsections of the code. Within each subsection, you will add your code to address that component. ```{r eval=FALSE, include=FALSE} ################################################################################ # Author: # # Description: # reads the champ all waves data from /data/raw # cleans up some key variables, and arranges them to prepare for all other tasks # creates champ_all_waves_initial_clean.Rds data file in /data ################################################################################ ################################################################################ # Load libraries and functions ################################################################################ # read the champ all waves data from /data/raw ################################################################################ # cleaning names and variables ################################################################################ # rearrange the data frame ################################################################################ # write out as champ_all_waves_initial_clean.Rds ################################################################################ ``` # **Step 2: Coding in the Initial Cleaning File** ## **Adding Author and Description Details** Locate the description section of "champ_all_waves_initial_clean.R". The purpose of such content is to *provide authorship*, to *describe the goals of the script* so that your further self and others understand its purpose, and to *constrain you* from doing too much in a single script. 1. Add your first and last name ## **Loading Libraries and External Functions** Locate the section for loading libraries and functions. 1. Load any libraries that you need to carry out necessary tasks. Once you realize that you need a library, load it here. Do not load libraries that you do not need. 2. Source your directory of external/custom functions from `/r/functions`. Do no load scripts individually. ## **Importing Raw Data** Locate the section for reading the initial data. 1. Using the **{here}** library, read the "champ_all_waves_practice_subset.Rds" data that you have in `/data/raw`. 2. Once you know you can read it, assign it to: `CHAMP` ## **Cleaning** Locate the section for cleaning the data. 1. Make all variable names lowercase. 2. Remove the spaces in the `id_subject` vector variable. 3. Remove the spaces in the `id_school` vector variable. ## **Rearranging Variable Positions** Locate the section for rearranging variables. 1. Move `id_subject`, `id_school`, and `id_wave` to the first, second, and third variables in the data frame, respectively. **Note:** The steps above can be combined if you pipe your code using `|>`. ## **Exporting/Writing the Data Frame** Locate the section for exporting your data frame. 1. Write out your modified data frame as "champ_all_waves_initial_clean.Rds" in `/data`. # **Step 3: Creating a Mock Report** Rather than create a separate R Markdown report file to integrate your script files that accomplish the tasks outlined above (as you would for your team project), this homework file will serve in it's place. You will write text that includes in-line `R` objects as you have for a previous class exercise. 1. In the code block below, first source your "champ_all_waves_initial_clean.R" by utilizing **{here}**. 2. Then read "champ_all_waves_initial_clean.Rds" using **{here}** and assign it to `CHAMP2`. ```{r} # source script # read and assign ``` *Do not remove the following statements containing in-line `R` objects. These statements should execute when you knit your file if you have completed the previous correctly.* My sample data set contains `r length(unique(CHAMP2$id_subject))` participants. Their ids are `r unique(CHAMP2$id_subject)`. Their school code(s) are `r unique(CHAMP2$id_school)`. *Now, type a few sentences that describe some detail about the data set. I encourage you to try embedding at least one in-line R object.* # **Adding, Committing, and Pushing to Git** Once completed, practice using Git. - add, commit with a message: "champ_all_waves_initial_clean.R" - add, commit with a message: "champ_all_waves_initial_clean.Rds" - add, commit with a message: your HW3 .Rmd and .HTML files - push all of your commits to your exercise repository on GitHub. In class, I will ask to see these commits in your GitHub repository. Finally, knit an `html` file and upload to: https://claremontmckenna.app.box.com/f/026ed41483fb4a739f0ddfc7fbf8fd01