Please download the answer file and edit it on Rstudio. Write your student number in the correct place at the beginning of the answer file. You should be able to Knit HTML and get the same results as the document you have in paper. Please do Knit often and verify that your document has no errors. If your document does not Knit, you will not have full grade.

When you finish, send the answers.Rmd file to my mailbox (andres.aravena+cmb@istanbul.edu.tr). Be sure to use the correct email address and send only one file.

IMPORTANT: Write your student number in the correct place at the beginning of the answer file.

1 Creating vectors

1.1 Write the R command to produce this vector

[1] "x" "y" "y" "z" "z" "z"
# write your answer here

1.2 Write the R command to produce a vector with numbers 0, 0.1, 0.2, …, 0.9, 1.0

 [1] 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0
# write your answer here

1.3 Create a named vector, with the values 1, 2, 3, and 4, and with names “one”, “two”, “three”, and “four”.

Assign this vector to the variable x. Then show the content of x

  one   two three  four 
    1     2     3     4 
# write your answer here

1.4 Using the name as index, show the value of two in the vector x

two 
  2 
# write your answer here

2 Using indices

Your R system has already some vectors to be used for exercises. One of them is letters, containing the English alphabet

2.1 Write the command to show the content of letters

 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s"
[20] "t" "u" "v" "w" "x" "y" "z"
# write your answer here

2.2 Find the second element

[1] "b"
# write your answer here

2.3 Find the 10th element

[1] "j"
# write your answer here

2.4 Make a logic vector that is TRUE for the vowels in letters. In English the vowels are c("a", "e", "i", "o", "u")

 [1]  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
[13] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE
[25] FALSE FALSE
# write your answer here

2.5 Find the last element

[1] "z"
# write your answer here

2.6 Find the first 6 elements

[1] "a" "b" "c" "d" "e" "f"
# write your answer here

2.7 Find the last 6 elements

[1] "t" "u" "v" "w" "x" "y" "z"
# write your answer here

2.8 Find all except the first 3 elements

 [1] "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q" "r" "s" "t" "u" "v"
[20] "w" "x" "y" "z"
# write your answer here

2.9 Find the elements in positions 5, 7, 9, …, 15

[1] "e" "g" "i" "k" "m" "o"
# write your answer here

3 USA states

Other vectors already included in R are used to describe USA states. They include state.area and state.name, which we will use in this exercise.

In the future we will work with other countries’ data, but these are easier to use for this homework.

3.1 Write the R command to create a logic vector, which is TRUE for the elements of state.area that are greater than 5E4

 [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE FALSE  TRUE
[13]  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE
[25]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE  TRUE
[37]  TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE  TRUE FALSE
[49]  TRUE  TRUE
# write your answer here

3.2 Show the first 4 elements of the vector state.name

[1] "Alabama"  "Alaska"   "Arizona"  "Arkansas"
# write your answer here

3.3 Show all the elements of the vector state.name, except the first 40

 [1] "South Dakota"  "Tennessee"     "Texas"         "Utah"         
 [5] "Vermont"       "Virginia"      "Washington"    "West Virginia"
 [9] "Wisconsin"     "Wyoming"      
# write your answer here

3.4 Show the elements of the vector state.name corresponding to states whose area is greater than 2E5

[1] "Alaska" "Texas" 
# write your answer here