Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

\"### [4 points] \'volume-changes() **(d** Write the volume_changes) function th

ID: 3754771 • Letter: #

Question

"### [4 points] 'volume-changes() **(d** Write the volume_changes) function that computes the number of times successive values change. Arguments: - data_points: A vector of numeric values. * te - **Output:** Number of times volume increases or decreases **Design Notes:** When we talk about detecting a "change", we are looking for a point where values switch from one value to another. The change could be either positive or negative depending on whether the sequence is increasing or decreasing. As an example, consider X = c(0, 0, 1, 1, 0, 0, 0, 1). Here there are three changes that take place. e.g. 0 goes to 1, '1' goes back to 0, and goes to 1 As a result, the function would report there were **3** changes. If we take the difference between successive values, we would get a detection vector that had detect - c0, 1, 0, -1, 0, 0, 1)'**Note:** The number of values in the detect' vector is length(x) -1".

Explanation / Answer


##Function execution##
##Take the input vector##

volume_changes <- function(data_points)
{
  
##Initialize the variable, volume_change as 0##
##It will store the number of times there will be a change in sequence##
volume_change=0
  
##Run the for loop, one less than the length of input vector##
for(i in 1:(length(data_points)-1))
{
  
##Compare successive data points##
if(data_points[i]!=data_points[i+1])
{
  
##If they aren't same, increase the counter variable
volume_change=volume_change+1
}
}
  
##Print the number of volumne changes##
print("Number of volume changes")
print(volume_change)
}

###Declare the input vector##
input_array<-c(0,0,1,2,0,0,-1,-1,3,3,3,0,0)

##Call the function and pass the vector##
volume_changes(input_array)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote