#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION:
#
# Write an R command that displays all the even numbers between 100 and 1000 (including 100 and 1000)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
39 37. Practice Questions - TOPIC: Vectors2
39.1 Vectors
QUESTION 1 (vectors, rep/seq/:/etc)
QUESTION 2 (vectors , rep/seq/:/etc)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION:
#
# Write an R command that displays the values: 10, 13, 16, 19, 22, etc. There
# should be 500 numbers in all.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 3. (vectors , rep/seq/:/etc)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION
#
# Write an R command that displays alternating values of positive and
# negatives of 1,2,3 ie.: 1,2,3,-1,-2,-3,1,2,3,-1,-2,-3,1,2,3 ... etc.
# There should be a total of 60 numbers in all.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 4. (vectors , recycling)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 4 TOPICS: vectors , recycling ####
#
# Write an R command that displays all the powers of 2 from
# 2 to the power of minus 20 (i.e. -20) until
# 2 to the power of positive 20 (i.e. +20)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 5 (vectors , indexingWithLogicalValues)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION
#
# Write an R command that displays every entry in the vector x whose value is 10 or more.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 6 TOPICS: vectors , indexingWithLogicalValues
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 6 TOPICS: vectors , indexingWithLogicalValues ####
#
# x and y are two numeric vectors whose lengths are equal.
# Show every value from the vector, x, that is less than the corresponding value in the vector y
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 7 TOPICS: vectors , round , runif , RHelpPages
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 7 TOPICS: vectors , round , runif , RHelpPages ####
#
# SOME BACKGROUND - runif function
#
# The runif function returns a numeric vector that contains "random numbers
# with a uniform distribution". The R help page for runif shows that the
# arguments and default values for those arguments are:
# runif(n, min=0, max=1)
# where
# n is the number of numbers to generate
# min is the smallest value that a number could have
# max is the largest value that a number could have.
#
# EXAMPLES:
#
# > # return a vector of 3 random numbers whose values fall between 0 and 10
# > runif(3,0,10)
# [1] 3.785233 9.672244 2.857430
#
# > # return a vector of 10 random numbers whose values fall between -5 and +5
# > runif(10,-5,5)
# [1] -1.84032071 4.28685602 2.59656498 -1.09880205 -3.90202237 -1.89618831 3.37193245
# [8] 0.08757248 -1.10848900 -1.90661883
#
# > # return a vector of 5 random numbers. The min and max are not specified so
# > # use the default values of min (ie. 0) and max (i.e. 1)
# > runif(5)
# [1] 0.4098594 0.8771700 0.5610475 0.8928674 0.4863841
#
# WHAT YOU HAVE TO DO:
#
# Generate 10 random numbers that are between 50 and 51. The numbers should have
# 2 values after the decimal point. (HINT: use the runif and the round
# functions). Note that every time you run this command the actual numbers will
# be different.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 8 TOPICS: vectors , c
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 8 TOPICS: vectors , c ####
#
# Insert the number 5 in the beginning of the vector named x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 9 TOPICS: vectors , c , length
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 9 TOPICS: vectors , c , length ####
#
# Insert the number 6 at the end of the vector named x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 10 TOPICS: vectors , c , indexingWithNumbers
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 10 TOPICS: vectors , c , indexingWithNumbers
#
# x is a vector that contains 11 or more values.
# Insert the number 7 between the 10th and 11th values in the vector named x.
#
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 11 TOPICS: vectors , c , indexingWithNumbers
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 11 TOPICS: vectors , c , indexingWithNumbers ####
#
# The vector x contains 10 values. Swap the first 5 and
# the last 5 values in x. For example, if x contains the
# values 1,2,3,4,5,6,7,8,9,10 then after your command runs,
# x should contain the values 6,7,8,9,10,1,2,3,4,5
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 12 TOPICS: namedVectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 12 TOPICS: namedVectors ####
#
# Grades is a named vector that contains test scores.
# The names of the entries are the names of the students.
# Exchange the value of Tom's grade with Joe's grade where
# "tom" and "joe" are the names of the values that contain
# the grades for Tom and Joe.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 13 TOPICS: namedVectors , indexingWithLogicalValues
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 13 TOPICS: namedVectors , indexingWithLogicalValues ####
#
# Grades is a named vector that contains test scores. The names
# of the entries are the names of the students. Change susan's name to sue
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 14 TOPICS: vectors , indexingWithNumbers , vectorAssignment
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 14 TOPICS: vectors , indexingWithNumbers , vectorAssignment ####
#
# Exchange the 4th and 7th value in the vector nums.
#
# a. Do this using 3 different commands. Hint, you may create new variables.
# (Hint, you may create new variables. For example, I'll start you off:
# fourth <- x[4]
# seventh <- x[7]
# # fill in the rest of the R code to answer the question.
#
# b. Do this using only a single R command
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 15 TOPICS: vectors , indexingWithNumbers , length
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 15 TOPICS: vectors , indexingWithNumbers , length
#
# Display the last value from the vector x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 16 TOPICS: vectors , indexingWithNumbers , length
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 16 TOPICS: vectors , indexingWithNumbers , length
#
# Display the 2nd to last value in x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 17 TOPICS: vectors , indexingWithNumbers , mean , orderOfOperations
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 17 TOPICS: vectors , indexingWithNumbers , mean , orderOfOperations ####
#
# Display the average of the last 5 values in x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 18a TOPICS: vectors , vectorArithmetic
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 18a
# TOPICS: vectors, vectorArithmetic, seqColon, indexingWithLogicalValues, length, sciNotation, Inf
#
# Inf is used for "Infinity"
#
# R can only work with numbers up to a certain size. Any value that is more
# than the maximum is returned as Inf (which stands for Infinity).
#
# Example:
#
# SCIENTIFIC NOTATION
#
# By default R displays very large and very small numbers using a mathematical
# notation called "scientific notation". "Scientific notation" is just a
# fancy way of writing very large and very small numbers using very little
# typing.
#
# To understand "scientific notation", let's start with a simple example.
# 1e+3 is the scientific notation way to write the number 1000.
# 1e+3 can be understood as 1*10^3 (as explained in the next paragraph)
#
# People who are not familiar with scientific notation might read
# "1e+3" as "one e plus 3". However, that is NOT the right way to read it.
# Instead, whenever you see "e" in scientific notation, read it as though
# instead of "e" it said "... times 10 to the power of ...", so "1e+3" should
# be read as "one times 10 to the power of positive 3"
# i.e., "1e+3" is the same as 1*10^3.
# ( By the way, the letter "e" is used because, "e" is short for "exponent". )
#
# In a similar way, 2.3e+12 is the scientific notation way of writing the
# number 2300000000000 which is the same as "2.3 times 10 to the power of 12"
# i.e. 2.3*10^12
#
# To see that R "understands" scientific notation, just type 1e+3 into R.
# Because 1e+3 is the same as 1000, R just displays 1000. For example:
#
# > 1e+3 # this is scientific notation for 1000.
# [1] 1000
#
# By default if a number is small enough then R displays it in it's "regular"
# form (i.e. NOT in scientific notation). However, if a number is very large or
# extremely small, then R displays the number in scientific notation:
#
# > # "regular numbers" get displayed normally
# > 1000
# [1] 1000
#
# > # very large numbers get displayed in scientific notation (with a positive exponent)
# > 1000000000000
# [1] 1e+12
#
# > # extremely small numbers get displayed in scientific notation (with a negative exponent)
# > 0.0000000000001
# [1] 1e-13
#
# -----------------------------------------------------------------------------
# Write code that answers the following question:
#
# What is the highest power of 4 that is less than one million?
#
# Your code should produce the answer 9.
#
# The answer is 9 since 4^9=262,144 which is less than 1 million
# but 4^10=1,048,576 is more than one million.
#
# Write R code to calculate this answer (i.e. 9) automatically.
# Your code should work for any base that is between 2 and 1000 (because 1000 is the
# square root of one million), not only for a base of 4. For example, if instead of
# the number 4, your code used the variable "n", your code should print the
# highest power of "n" that is less than one million. You may write the answer
# using several lines of R code.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 18b TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 18b
# TOPICS: vectors, vectorArithmetic, seqColon, indexingWithLogicalValues, length
#
# Same as previous question, but this time n contains a "base" as before and
# x contains the maximum value (In the previous question this was one million.
# In this question it can be any number that is contained in x.) The question
# now is what is the maximum whole-number power that n can be raised to whose
# result is less than x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 19 TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 19
# TOPICS: vectors, seqColon, indexingWithNumbers, vectorArithmetic
#
# nums is a vector that contains 100 numbers.
#
# Use nums to create a vector that contains 50 numbers, as described below.
# The first value should be the sum of the first two numbers from nums.
# The 2nd value should be the sum of the 3rd and 4th values from nums.
# For example, if nums contains 1,2,3,4,5,6 ... 99,100, then your answer
# should contain 3,7,11 ... 199.
#
# For example, if nums contains
# 3,6,2,8,1,-2, ... ninety-one-other-numbers ... 8,5,-5,2
#
# then your answer should contain
# 9,10,-1, ... forty-five-other-numbers ... 13,-3.
#
# You may write the answer using several lines of R code.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 20 TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 20
# TOPICS: vectors, ==and!=, indexingWithLogicalValues, seqColon
#
# x and y are vectors that each contain 5 numbers.
#
# PART A: Show the values from x whose corresponding values in y are the same.
# PART B: Show the position numbers that contain the same values in x and in y.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 21 TOPICS: vectors, sumMean, indexingWithLogicalValues
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 21
# TOPICS: vectors, sumMean, indexingWithLogicalValues
#
# Show all values from the vector x that are greater than the average of the values in x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 22 TOPICS: vectors, sumMean, roundTruncCeilingFloor
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 22
# TOPICS: vectors, sumMean, roundTruncCeilingFloor
#
# The sd() function returns the standard deviation of a vector.
# Show all of the numbers in the vector x that are at least 1.5 standard deviations
# away from the mean of x. You can show the numbers in any order you like. They do not
# have to be in the same order that they appear in the vector x.
#
# HINT: Standard Deviation is a concept that is covered in statistics. If you didn't take
# stats yet, I can understand why you're confused. Bottom line, is that sd(c(3,10,76,32,23,31))
# will return a SINGLE number that is called the "standard deviation" of the values
# 3,10,76,32,23,31. sd(c(3,10,76,32,23,31) is 25.67. The mean of those same values
# is 29.16. Therefore, numbers that are at least 1.5 standard deviations away from the mean are
# greater than 29.16 + 1.5 * 25.67 = 67.67
# or less than 29.16 - 1.5 * 25.67 = -9.34
# Therefore, if x contained the numbers shown, then you should only display the number 76 as
# that is the only number that is outside of the specified range.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 23 TOPICS: vectors, parallelVectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 23
# TOPICS: vectors, parallelVectors
#
# The following variables are parallel vectors that contain info
# about 4 different rectangles.
#
# colors <- c("red","blue","green","yellow)
# lengths <- c(4,5,6,7)
# widths <- c(5,6,2,4)
#
# In other words:
# the 1st rectangle is "red", it's length is 4 and it's width is 5
#
# the 2nd rectangle is "blue", it's length is 5 and it's width is 6
#
# the 3rd rectangle is "green", it's length is 6 and it's width is 2
#
# the 4th rectangle is "yellow", it's length is 7 and it's width is 4
#
# QUESTIONS:
#
# The actual numbers and colors shown above are just an example.
# Your answers must work even if the vectors contain different
# numbers and colors and even if the vectors contains fewer or more values.
#
# a. Show the AREAS of all the rectangles.
#
# Given the example data above,
# your code should evaluate to: 20 30 12 28
#
# b. Show the COLORS of the rectangles whose areas are at least 25.
#
# Given the example data above,
# your code should evaluate to: "blue" "yellow"
#
# c. Show the COLORS of the rectangles
# whose length is at least 5
# or whose width is at least 5.
#
# Given the example data above,
# your code should evaluate to: "red" blue" "green" "yellow"
#
# d. Show the COLORS of the rectangles
# whose length and width are both at least 5.
#
# Given the example data above,
# your code should evaluate to: "blue"
#
# e. Show the COLORS of the rectangles whose area is at least 25.
#
# Given the example data above,
# your code should evaluate to: "blue" "yellow"
#
# f. Show the LENGTHS of the blue rectangles whose area is at least 25
#
# Given the example data above,
# your code should evaluate to: 5
#
# g. Show the LENGTHS of the rectangles whose area is at least 25
# and whose color is any one of blue, green or yellow.
#
# Given the example data above,
# your code should evaluate to: 5 7
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 24 TOPICS: vectors, parallelVectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 24
# TOPICS: vectors, parallelVectors
#
# The vector "roomDimensions" is used to store the lengths, widths and
# heights of several rooms in the following format:
# lengthRoom1,widthRoom1,heightRoom1,lengthRoom2,widthRoom2,heightRoom2, etc.
#
# FOR EXAMPLE, the following code :
#
# > roomDimensions <- c(10,4,10,11,5,9,12,5,10.5,8,5,9.5)
#
# represents information about four different rooms with the following dimensions.
#
# first room: length is 10, width is 4, height is 10
# second room: length is 11, width is 5 height is 9
# third room: length is 12, width is 5, height is 10.5
# fourth room: length is 8, width is 5, height is 9.5
#
# Different numbers may be assigned to roomDimensions, but the structure is as
# described above.
#
# ANSWER PARTS a,b,c,d,e SHOWN BELOW
# The answer to (a) should display: 4
# The answer to (b) should display: 11 5 9
# The answer to (c) should display: 40 55 60 40
# The answer to (d) should display: 2 3
# The answer to (e) should display: 9 10
#
# NOTE that your code for (a),(b),(c),(d) and (e) should work no
# matter what values are placed in the variable, roomDimensions
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 24a (see the intro to question 24 above) # TOPICS: vectors, length
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 24a (see the intro to question 24 above)
# TOPICS: vectors, length
#
# Write R code to display how many "rooms" are represented in the vector,
# i.e. 1/3 of the number of values in the vector.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 24b (see the intro to question 24 above) TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 24b (see the intro to question 24 above)
# TOPICS: vectors
#
# Write R code to display the length, width and height of the nth room
# where n is a variable that contains a number. For example, if "n" contains
# the number 4 then your code should display the 3 numbers that represent the
# length, width and height of the 4th room.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 24c (see the intro to question 24 above) # TOPICS: vectors, parallelVectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 24c (see the intro to question 24 above)
# TOPICS: vectors, parallelVectors
#
# Write R code to display the number of square feet of floor space in each room.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 24d (see the intro to question 24 above) TOPICS: vectors, parallelVectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 24d (see the intro to question 24 above)
# TOPICS: vectors, parallelVectors
#
# Write R code to display the room numbers of those rooms that have
# at least 50 square feet of floor space.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 24e (see the intro to question 24 above) TOPICS: vectors, parallelVectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 24e (see the intro to question 24 above)
# TOPICS: vectors, parallelVectors
#
# Write R code to display the heights of those rooms that have
# at least 50 square feet of floor space.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 25 # TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 25
# TOPICS: vectors
#
# Display the sum of the squares of the numbers in the vector nums.
# For example, if nums contains the values 4 2 and 5 then your command should
# display the number 45, (i.e. 16 + 4 + 25)
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 26 TOPICS: vectors, indexingWithLogicalValues, vectorAssignment
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 26
# TOPICS: vectors, indexingWithLogicalValues, vectorAssignment
#
# Grades is a vector that contains grades on a test.
# Modify the vector, grades, by adding 5 points to all grades that are below 60.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 27 TOPICS: vectors, indexingWithNumbers
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 27
# TOPICS: vectors, indexingWithNumbers
#
# Reverse the contents of the vector x. DO NOT USE THE rev FUNCTION.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 28 TOPICS: vectors, mean, length, indexingWithLogicalValues
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 28
# TOPICS: vectors, mean, length, indexingWithLogicalValues
#
# grades is a vector that contains grades on a test. Display the number of students
# whose grade is equal to the average grade. For example, if grades contains
# c(80,85,85,85,90) then the answer should be 3 since the average is 85 and 3 students
# received exactly and 85.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 29 TOPICS: vectors, seqOrColon, minMax
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 29
# TOPICS: vectors, seqOrColon, minMax
#
# store in the vector nums a sequence of values from the smallest value in the
# vector x to the largest value in x. For example if x would contain c(7,8,7,3,5),
# your code should set the value of nums to the sequence 3 4 5 6 7 8
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 30 TOPICS: vectors, minMax, c
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 30
# TOPICS: vectors, minMax, c
#
# Write a single command that shows the lowest and the highest values from the
# vector x. For example if x contains c(20,-5,-2,40,25,-2,18), then your answer
# should display -5 40
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 31 TOPICS: vectors, roundTruncCeilingFloor, sqrt, ==and!= , %/%and%%
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 31
# TOPICS: vectors, roundTruncCeilingFloor, sqrt, ==and!= , %/%and%%
#
# Determine if the number stored in n is a "perfect square". For example 25 is
# a "perfect square" because 5*5 is 25. Similarly, 49 is a perfect square because
# 7*7 is 49. However, 50 is NOT a perfect square since its square root is not an integer.
# Your code should display the value TRUE is n is a perfect square and FALSE if n is
# not a perfect square. Hint: the sqrt(x) function returns the square root of x.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 32 TOPICS: vectors, roundTruncCeilingFloor, &|, ==!=
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 32
# TOPICS: vectors, roundTruncCeilingFloor, &_|, ==_!=
#
# Write a command that shows the numbers in the vector nums that are both even
# and perfect squares. For example, if nums contains c(81, 6, 36, 10, 4, 25)
# then your answer should display 36 4
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 33 TOPICS: vectors
############################################################################################################.
# NOTE: The sort(x) function will return a vector with the values from the vector x in sorted order.
# The unique(x) function will return a copy of the vector x with all of the duplicate values removed.
# These functions will help you to answer the following questions
############################################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 33
# TOPICS: vectors
#
# Write a command that displays the 2nd lowest value in the vector x. If the lowest value appears
# more than once in the vector, then your code should display that value. For example, if x contains
# the numbers 7 3 3 7 3 5 20, the function should return the number 3. Even though 3 is the lowest
# value, it appears more than once, so in that sense, it is the 2nd lowest value.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 34 TOPICS: vectors
############################################################################################################.
# NOTE: The sort(x) function will return a vector with the values from the vector x in sorted order.
# The unique(x) function will return a copy of the vector x with all of the duplicate values removed.
# These functions will help you to answer the following questions
############################################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 34
# TOPICS: vectors
#
# Write a command that displays the 2nd lowest value in the vector x. For this question, you
# should ignore duplicate values. For example, if x contains the numbers 7 3 3 7 3 5 20, the function
# should return the number 5. Even though 3 appears more than once, 5 is the 2nd lowest value.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 35 TOPICS: vectors
############################################################################################################.
# NOTE: The sort(x) function will return a vector with the values from the vector x in sorted order.
# The unique(x) function will return a copy of the vector x with all of the duplicate values removed.
# These functions will help you to answer the following questions
############################################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 35
# TOPICS: vectors
#
# Write a command that displays the n lowest values in the vector x where n is
# a variable that contains a positive integer. The values should be displayed
# in increasing order.
#
# For example if x contains c(67,2,40,5,2,99) and n contains the number 3 then
# the command should display the numbers 2 2 and 5
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 36 TOPICS: vectors
############################################################################################################.
# NOTE: The sort(x) function will return a vector with the values from the vector x in sorted order.
# The unique(x) function will return a copy of the vector x with all of the duplicate values removed.
# These functions will help you to answer the following questions
############################################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 36
# TOPICS: vectors
#
# Same as previous question, but the numbers should be in decreasing order.
# For example, given the values from the previous question, the answer should
# display 5 2 2. Hint, see the help for the sort command and focus on the
# "decreasing" argument to sort.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 37 TOPICS: vectors
############################################################################################################.
# NOTE: The sort(x) function will return a vector with the values from the vector x in sorted order.
# The unique(x) function will return a copy of the vector x with all of the duplicate values removed.
# These functions will help you to answer the following questions
############################################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 37
# TOPICS: vectors
#
# Same as previous question, but the numbers should be displayed in the same order
# as they appear in the original vector x. Given the same values from the previous
# question, the answer should display the numbers 2 5 2 in that order.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 38 TOPICS: vectors
############################################################################################.
# QUESTION_GROUP:
#
# (The next two questions are related to each other. I would have numbered them a,b,etc but
# I thought it would be better for each question to have its own number.)
##########################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 38
# TOPICS: vectors
#
# x and y each contain a single integer. nums is a vector that contains many numbers.
# You are told that the value of x is guaranteed to be less than the value of y.
# Change the vector nums so that it only contains the values that are in the range
# between x and y (including x and y). For example, if x contains 3, y contains 7 and
# nums contains c(10,3,2,11,6,4,1) then your code should change the value of nums to a vector
# containing 3 6 and 4..
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 39 TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 39
# TOPICS: vectors
#
# Same as previous question, except for this question the value in x may be less than,
# greater than or equal to y. Hint: use the sort() function to isolate the smaller
# of x and y and the larger of x and y. Then proceed similarly to the way you answered
# the previous question.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 40 TOPICS: vectors
############################################################################################.
# QUESTION_GROUP:
#
# The next few questions are related to each other.
# I would have numbered them a,b,etc but I thought it would be better
# for each question to have its own number.
############################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 40
# TOPICS: vectors
#
# nums is a vector that contains several numbers. n contains a single positive integer.
# Write code that "shifts" the values in nums over to the right "n" times. For example,
# if nums contains 10 20 30 40 50 60 70 80 90 100 and n is 2 then your command should
# reset nums to 90 100 10 20 30 40 50 60 70 80. If n were 3, your command should
# reset nums to 80 90 100 10 20 30 40 50 60 70
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 41 TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 41
# TOPICS: vectors
#
# Same as previous question, but the numbers at the end of nums should be
# removed and the beginning of nums should be filled in with "n" zeros. For example,
# if nums contains 10 20 30 40 50 60 70 80 90 100 and n is 2 then your command should
# reset nums to 0 0 10 20 30 40 50 60 70 80. If n were 3, your command should
# reset nums to 0 0 0 10 20 30 40 50 60 70
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 42 TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 42
# TOPICS: vectors
#
# Same as above, but replace the numbers at the beginning of nums with 1,2,3,etc.
# For example, if nums contains 10 20 30 40 50 60 70 80 90 100 and n is 2 then your
# command should reset nums to 1 2 10 20 30 40 50 60 70 80. If n were 3, your command
# should reset nums to 1 2 3 10 20 30 40 50 60 70
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 43 TOPICS: vectors
############################################################################################.
# QUESTION_GROUP:
# (The next few questions are related to each other. I would have numbered them a,b,etc but
# I thought it would be better for each question to have its own number.)
############################################################################################.
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 43
# TOPICS: vectors
#
# The vector nums contains several numbers. Display the values of nums without the
# smallest numbers. For example, if nums contains c(30,5,20,5,30,15) then your command
# should display 30 20 30 15(none of the 5's are displayed since 5 is the smallest number).
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
QUESTION 44 TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 44
# TOPICS: vectors
#
# Same as the previous question, but do not display any of the smallest or the
# largest numbers. For example, if nums contains c(30,5,20,5,30,15) then your command
# should display 20 15 (none of the 5's are displayed since 5 is the smallest number and
# none of the 30's are displayed since 30 is the largest number).
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##############################################################################################.
# END_OF_QUESTION_GROUP
##############################################################################################.
QUESTION 45 TOPICS: vectors
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# QUESTION 45
# TOPICS: vectors
#
# x and y are two vectors whose lengths are the same. Merge the contents of
# vector y into vector x in the following way. If x1,x2,x3,x4,... represent the
# initial values in x and y1,y2,y3,y4,... represent the values in y, then after
# your commands run, the values in x should be x1,y1,x2,y2,x3,y3,x4,y4,...
#
# For example, if x contains the values 1 2 3 4 and y contains the values 11 22 33 44
# then after your code runs the values in x should be 1 11 2 22 3 33 4 44.
# (You may use more than one command to accomplish this result).
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~