Due: Sunday, 08-Sept. at 8pm
Open RStudio and create a new project called “hw1-lastName”, replacing “lastName” with your last name.
Create a new R script and save it as “hw1.R” in the R project folder you just created.
Copy the following code to the top of this script, and fill out your name, GW Net ID, and the names of anyone you worked with:
# hw1.R # Name: Last, First # GW Net ID: your_GWNetID_here # I worked with the following classmates on this assignment: # 1) Name: Last, First # 2) Name: Last, First
Type all of your answers to the following questions in the “hw1.R” script. [point breakdown is listed by each problem]
After completing the questions, create a zip file of all files in your R project folder for this assignment and submit the zip file on Blackboard by the due deadline (note: to receive full credit, your submission must follow the above format of using a correctly-named R Project and
.R script). [5 pts]
Consider the following objects:
w <- TRUE x <- FALSE y <- FALSE z <- TRUE
Write code to answer the following questions:
! (x __ y) & ! (z __ y)
! (w __ y) | (z __ y)
Create objects to store each of the following values. Use names that make sense and are easy to understand:
Use the objects you created to calculate the following (you may create other, intermediate objects, but you may not use numbers in your solution):
Load the following string in R:
sentence <- 'The quick Brown fox Jumped over the Lazy dog'
Install and load the
stringr library, then use the
str_to_title() functions and the
cat() function to print out the following variations of the object
sentence that you just created (hint: you may want to first look up what the
str_to_title() functions do):
"the quick brown fox jumped over the lazy dog" "THE QUICK BROWN FOX JUMPED OVER THE LAZY DOG" "The Quick Brown Fox Jumped Over The Lazy Dog"
Max is looking to purchase a car and is deciding between a Toyota Prius and a Toyota Camry. He knows that based on his driving patterns, he can get an average fuel economy of 55 miles per gallon (mpg) of gasoline with the Prius, which sells for $27,600. He is also considering the cheaper Toyota Camry, which costs $24,000 but only gets 32 mpg on average. He knows he typically drives 15,000 miles each year. For the following questions, assume the price of gas will remain constant at $3.00 / gallon forever.
2once in your solution, otherwise you may only use the objects you defined in parts a) and b).
Load the following objects into R, then answer the questions below:
x1 <- 1 y1 <- 1 x2 <- 5 y2 <- 1 x3 <- 5 y3 <- 4
Suppose we fielded a survey that asked respondents to specify their marital status. The responses were recorded as one of the following:
"missing" means the respondent left the question blank.
Assume there is an object in your R environment called
marital_status that contains one of the above responses stored as a character. For each of the following, write a single line of code that uses the
marital_status object to create the desired new object (note that if you actually run your code in R for this exercise, you’ll get an error, because the
marital_status object doesn’t actually exist in your R environment):
TRUEif the participant is single and
TRUEif the participant is married or in a de facto relationship and
TRUEif the participant did respond to the question, but is not single.
TurtleGraphicslibrary, then use the following command:
turtle_init(). What happens?
turtle_move()function in the
turtle_init() turtle_move(distance = 10, direction = "forward") turtle_move(distance = 20, direction = "backward") turtle_reset() turtle_turn(angle = 90, direction = "right") turtle_move(distance = 10, direction = "forward") turtle_move(distance = 20, direction = "backward") turtle_reset()
TurtleGraphicspackage works, write code to produce the following image: