seq_1 <- seq(from = -10, to = 10, by = 2)
seq_2 <- seq(from = 0, 
             to = 100, 
             length.out = 1000)

# solution
my_sol <- max(seq_1+seq_2)
my_answers <- make_random_answers(my_sol)

#check_answers(my_answers)

Question

Calculate the sum between seq_1 and seq_2 vectors (see previous exercises). Did this operation work despite the different size of the vectors? Explain your answer. If it works, what is the highest value of the resulting vector?

exams::answerlist(my_answers, markup = "markdown")

Solution

Yes, it worked, but with a warning: _ "the length of the longest object is not a multiple of the length of the shortest object"_. The explanation is that whenever R encounters operations with different vector sizes, it uses the recycling rule, where the shortest vector is repeated as many times as necessary to match the size of the longest vector. In the book, see the section on numerical vectors for more details.


Meta-information

extype: schoice exsolution: r mchoice2string(c(TRUE, FALSE, FALSE, FALSE, FALSE), single = TRUE) exname: "numeric " exshuffle: TRUE



msperlin/afedR documentation built on Sept. 11, 2022, 9:49 a.m.