<- c("temp2010", "temp2011", "temp2012", "temp2013", "temp2014") list_temp
Assignment 1
Instructions
Please submit your assignment as html file to me via email. Please call your assignment: “yourname_assignment1.html”. For example, I would submit submit something called “popescu_assignment1.html”. Please make sure that it is all in lower case. Please answer all the questions below
1 Question
Remove the word “temp2011” from the following vector and create a new object
2 Question
What is the length of old vector? What about the new vector? Write code that helps you answer the question.
3 Question
Remove from the following list all the numbers between 30 and 60 (inclusive)
<-c(10, 20, 30, 40, 50, 60, 70) list_no
4 Question
Turn the following list into date objects
<-c("1901-01-16",
list_dates_1900s"1902-01-16",
"1903-01-16",
"1904-01-16",
"1905-01-16",
"1906-01-16",
"1907-01-16",
"1908-01-16",
"1909-01-16",
"1910-01-16")
5 Question
Select from the following list only the months before July (not including July)
<-c("1901-01-16", "1901-02-15", "1901-03-16", "1901-04-16", "1901-05-16", "1901-06-16", "1901-07-16", "1901-08-16", "1901-09-16", "1901-10-16", "1901-11-16", "1901-12-16", "1902-01-16", "1902-02-15", "1902-03-16", "1902-04-16", "1902-05-16", "1902-06-16", "1902-07-16", "1902-08-16", "1902-09-16", "1902-10-16", "1902-11-16", "1902-12-16") list_dates_1900s
6 Question
Remove the missing data from the following list
<- c("temp1", "temp2", NA, "temp4", "temp5") list_temp
7 Question
Calculate the mean from the following list of numbers
<-c(10, 20, 30, NA, 10, 20, NA) list_no
8 Question
Create a simple R script that takes a student’s score who got 81 as input and outputs their corresponding grade based on the following grading scale:
A: 90-100 B: 80-89 C: 70-79 D: 60-69 F: 0-59
Tip: Make use of if
and else
conditional statement.
Your output should read as follow:
[1] "Your grade is B."
9 Question
Now you have three students who got 81, 52, and 95 respectively. Update the script to get automatic letter grades.
Tip: Create a for
loop. Your output should read as follows:
[1] "Student 1 scored 81 and their grade is B."
[1] "Student 2 scored 52 and their grade is F."
[1] "Student 3 scored 95 and their grade is A."
10 Question
Repeat the previous exercise, but now, develop a function. Your code should produce the following output.
[1] "Student 1 scored 81 and their grade is B."
[1] "Student 2 scored 52 and their grade is F."
[1] "Student 3 scored 95 and their grade is A."