I suggest you create a new R Script "Exercises.R" that contains your solutions, so you don't intermix exercises with lecture notes.

  1. Why does the code below throw an error? Explain, and then solve the problem.
Oh_a_new_object <- 10
0h_a_new_object
# Error: <text>:2:2: unexpected symbol
# 1: Oh_a_new_object <- 10
# 2: 0h_a_new_object
#     ^
Oh_a_new_object <- 10
Oh_a_new_object # Exchange the number 0 for the letter O #<<
# [1] 10
  1. Create an object another_object2 that contains whole numbers from 123 to 131. The name of the function allowing you to do that is: and the assignment operator that creates the object is .
(another_object2 <- seq(123, 131))
# [1] 123 124 125 126 127 128 129 130 131
  1. Let R evaluate which of another_object2's elements is larger than 128 and smaller than 130.
another_object2 > 128 & another_object2 < 130
# [1] FALSE FALSE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE
  1. Add 2 to each element of another_object2 and check again which of its elements is larger than 128 and smaller than 130.
another_object2 <- another_object2 + 2
another_object2 > 128 & another_object2 < 130
# [1] FALSE FALSE FALSE FALSE  TRUE FALSE FALSE FALSE FALSE
  1. Create an object another_textobject that contains the sentence: "I am just another sentence."
(another_textobject <- "I am just another sentence.")
# [1] "I am just another sentence."
  1. What does R return if you try to multiply another_textobject by 3?

another_textobject <- another_textobject * 3
# Error in another_textobject * 3: non-numeric argument to binary operator
  1. Use the rep() function to repeat another_textobject five times. The argument to which you need to supply the value 5 is called .
rep(another_textobject, times = 5)
# [1] "I am just another sentence." "I am just another sentence." "I am just another sentence."
# [4] "I am just another sentence." "I am just another sentence."
  1. Use the rep() function to repeat another_object2 three times.
rep(another_object2, times = 5)
#  [1] 125 126 127 128 129 130 131 132 133 125 126 127 128 129 130 131 132 133 125 126 127 128 129 130 131 132 133
# [28] 125 126 127 128 129 130 131 132 133 125 126 127 128 129 130 131 132 133
  1. Use the rep() function to repeat each element of another_object2 three times. The argument to which you need to supply the value 3 is called .
rep(another_object2, each = 3)
#  [1] 125 125 125 126 126 126 127 127 127 128 128 128 129 129 129 130 130 130 131 131 131 132 132 132 133 133 133