# create question vector
= c(TRUE, T, "FALSE", F, 0, 1, "TRUE", 1, 0, TRUE, F, "true", "T", FALSE, T)
q1_vector
# <REPLACE THIS COMMENT WITH YOUR ANSWER>
Lab 1. Objects
Introduction to Labs
Each lab in this course will be completed through GitHub classroom. For each lab you will clone a template repo with a Quarto document within it (the source of the web page you are looking at now!). To complete the lab you will fill out that quarto document, and push your work to GitHub. Note however, that you should not wait to push until you are “done”; pushes are not like “turning in” an assignment. Each commit is a save point you can go back to if something doesn’t work, so you should commit and push often. The most recent push at the due date will be what is evaluated for proficiency according to the course standards.
Compared to worksheets, where individual functions are explained, labs remove that support and ask you to figure out the solutions to the problems on your own. This will involve referring back to past material in the class (not just the current week), reading documentation, and trying new things. The labs are purposefully made to go just a little beyond what we have covered thus far.
The good news is you’re not in it alone. The entirety of Friday class time is dedicated to giving you time and space to work on these problems. Additionally, you are actively encouraged to work with others. The final project is a group one, so use these labs to talk with several different groups and find people you think you work well with. However, you cannot simply copy code from your neighbor; make sure you understand why the code is working as it is. The content of this course will quickly build on itself, and if you leave one week without doing the work of understanding the material, the next week will only be harder. If your neighbor is also stuck, always remember the #coding-help
slack channel.
Getting the Lab Files
Click here to access the lab on Github Classroom: Github Classroom Assignment for Lab 1: Objects
Once you have created a repo, go to your repo page and click the green Code
button. In the resulting dropdown, make sure you select the SSH
version, and copy the link.
Once you have that link, you can clone the repo using R Studio, and it will create a project directory for you. You can do this by clicking the project drop down in the upper right corner, and selecting “New Project.” Rather than creating a entirely new project though, you’ll use R Studio to clone the repo from GitHub. Select Version Control, then Git, then past the SSH link you just copied above.
R will then open the new project, where you can work on this very Quarto document. Make sure to commit and push your changes often!
Overview
For this first lab we will be manipulating R objects is some novel ways. Most of the changes we make wouldn’t be something you would really want to do normally, but understanding how they work give you insight into R’s structures which will be helpful in developing your own later. For now, treat thee questions as puzzles to be solved.
In this lab, I am particularly looking at the Data Structures, Code Style, and git/GitHub standards. We will primarily be using data within R. However, you will need to install the jsonlite
package if you do not have it already. We will use it later when talking about lists to load some data.
Vectors
We’ll start by doing some normal sub-setting with vectors.
# <REPLACE THIS COMMENT WITH YOUR ANSWER>
# get final summed value of 7
sum(q2_vector)
Error in eval(expr, envir, enclos): object 'q2_vector' not found
Lists
For the section on lists we will be working with some JSON data regarding who is presently on in space1. Read it into your environment using the following code:
= jsonlite::read_json("http://api.open-notify.org/astros.json") current_space
We now have a list object containing all the people currently in the great void above us, including their names and what vessel they are on.
# <REPLACE THIS COMMENT WITH YOUR ANSWER>
# <REPLACE THIS COMMENT WITH YOUR ANSWER>
Now that we have just the people isolated, we’re going to start working on turning this list into a dataframe.
# <REPLACE THIS COMMENT WITH YOUR ANSWER>
Now that we have a named vector, we can create a dataframe from it.
# <REPLACE THIS COMMENT WITH YOUR ANSWER>
Challenge Question
At the end of every lab there will be one or more challenge questions. These questions are more difficult than others, and will often take some time. However, they will also frequently give you an opportunity to move higher on the standards matrix than other questions in the lab.
Given this is the first lab and we don’t have much content to work with, this one is primarily just for fun.
# <REPLACE THIS COMMENT WITH YOUR ANSWER>
Footnotes
Thanks to Open Notify for making this data easily accessible.↩︎