Homework 1 - Getting Started

Due: Jan 24 by 11:59pm

Weight: This assignment is worth 4% of your final grade.

Purpose: The purposes of this assignment are to:

  • Make sure you understand what you need to do to succeed in this class
  • Make sure you have properly set up the software and tools we will use this semester
  • Get started practicing basic concepts with R.

Skills & Knowledge: After completing these exercises, you should:

  • Be familiar with the main course tools: Slack, R, and RStudio.
  • Be familiar how to use R projects to stay organized.
  • Be able to use R to create and store values as objects with meaningful names.
  • Know how to compare values in R.
  • Know how to use arithmetic, relational, and logical operators in R.
  • Know the distinctions between how R handles different types of data types (numbers, strings, & logicals).

Assessment: Each question indicates the % of the assignment grade, summing to 100%. The credit for each question will be assigned as follows:

  • 0% for not attempting a response.
  • 50% for attempting the question but with major errors.
  • 75% for attempting the question but with minor errors.
  • 100% for correctly answering the question.

The reflection portion is always worth 10% and graded for completion.

Rules:

  • Problems marked SOLO may not be worked on with other classmates, though you may consult instructors for help.
  • For problems marked COLLABORATIVE, you may work in groups of up to 3 students who are in this course this semester. You may not split up the work – everyone must work on every problem. And you may not simply copy any code but rather truly work together and submit your own solutions.

Readings

The readings from the last week will serve as a helpful reference as you complete this assignment. You can review them here:

1) Class setup [SOLO, 10%]

For this class, you’ll need to install some software and register for some tools. You should have already done this, but in case you haven’t,go to the course software page to get set up.

Once you have joined the class slack, make a post to the #welcome channel introducing yourself - provide your name, year / program, and something interesting about yourself.

2) Getting familiar with the course [SOLO, 10%]

Follow Snoop’s advice and read the entire Course Syllabus (actually read the whole thing). Then review the schedule and make sure to note important upcoming deadlines.

3) Staying organized [SOLO, 10%]

Open RStudio and create a new R project called “hw1” (see the reading for details on how to do this). Within your project, create a new R script (a “.R” file) and save it as “hw1.R”. When you save it, it should show up in the R project folder you just created. Finally, copy the following code to the top of this script and fill out your name, netID, and the names of anyone you worked with on this assignment (your netID is the part of your email address before "@gwu.edu"):

# Name:  Last, First
# netID: Insert your netID here

# I worked with the following classmates on this assignment:
# 1) Name: Last, First
# 2) Name: Last, First

Write your responses to all other questions in this assignment in your R file.

4) Objects & Operators: Converting Time [COLLABORATIVE, 20%]

Create objects to store each of the following two values - be sure to use meaningful variable names when creating your objects:

  • The number of seconds in a minute
  • The number of minutes in an hour
  • The number of hours in a day
  • The number of days in a typical year (not a leap year)

Now, say you have another object called time_in_seconds that contains an integer number of seconds (for example, time_in_seconds <- 8675309). Write code to convert the value stored in time_in_seconds into the units described below. Your solution may only use arithmetic operators and the objects you created (i.e. you may not use any numbers). You may also use the new objects you create in sequential order. For example, you may use the object created in part a) to create the object in part b), and so on.

  1. The value of time_in_seconds in minutes
  2. The value of time_in_seconds in hours
  3. The value of time_in_seconds in days
  4. The value of time_in_seconds in years

5) Logical and relational operators [SOLO, 20%]

Consider the following objects:

w <- FALSE
x <- TRUE
y <- FALSE
z <- TRUE

Write code to answer the following questions:

  1. Write a statement with logical operators that compares the objects x, y, and z and returns TRUE
  2. Write a statement with logical operators that compares the objects x, y, and z and returns FALSE
  3. Fill in relational operators to make the following statement return TRUE:

! (x __ y) & ! (z __ y)

  1. Fill in relational operators to make this statement return FALSE:

! (w __ y) | (z __ y)

6) Data types [COLLABORATIVE, 20%]

Consider the following objects:

number    <- typeof('3')
character <- typeof(7)
false     <- typeof("FALSE")
true      <- typeof(TRUE)

Write code to answer the following questions:

  1. Write a statement with both relational & logical operators that compares the four objects number, character, false, and true and returns TRUE.
  2. Write a statement with both relational & logical operators that compares the four objects number, character, false, and true and returns FALSE.

7) Read and reflect [SOLO, 10%]

Read and reflect on the following readings to preview what we will be covering next:

Afterwards, reflect on what you’ve learned while going through these readings and exercises. Is there anything that jumped out at you? Anything you found particularly interesting or confusing?

In a comment (#) in your .R file, write at least a paragraph about your thoughts, and include at least one question. This can be on what you’ve learned and any questions or points of confusion you have about what we’ve covered thus far. This can be related to this assignment, next week’s readings, things going on in the world that remind you something from class, etc. If there’s anything that jumped out at you, write it down.

Some thoughts you may want to try in your reflection:

  • “I used to think ______, now I think ______ 🤔”
  • Discuss some of the key insights or things you found interesting in the readings or recent class periods.
  • Connect the course content to your own work or projects you’re working on.

Submit

Create a zip file of all the files in your R project folder for this assignment, then submit your zip file on the corresponding assignment submission on Blackboard.