Question: Task 1 Please generate a vector of the following values: 12,32,33,44 and assign this vector to a variable x. Then extract the first element and
Task 1
Please generate a vector of the following values:
12,32,33,44
and assign this vector to a variable x.
Then extract the first element and the last element from this vector
Please use RStudio program
Task 2
Following the previous question, please use a for loop to calculate the sum of all elements in the vector x.
Task 3
Check the length of the vector x.
If the length is greater than 2, then remove the last element.
Keep doing this until the length is no longer greater than 2.
Hint: to remove the last element of vector x, you can use x[1:length(x)-1]. To update the vector x after removing the last element, use x= x[1:length(x)-1]. Basically, we first remove the last element from x and then assign the leftovers to the variable x again.
You will need the repeat and the break statement mentioned in section 10 of the code snippet.
Please use RStudio
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
