Describe this function

Hi, can someone please describe to me what the following lines of code do. Additionally, can you find and apply this code to a particular scenario. Thanks

OpSp = function(y,x){
n = length(y)
s = n - 1
xs = sort(x)
ci = rep(0,s)
ssri = rep(0,s)
for (i in 1:s){
ci[i] = (xs[i] + xs[i+1])/2
y1 = y[x<ci[i]] - mean( y[x<ci[i]] )
y2 = y[x>ci[i]] - mean( y[x>ci[i]] )
ssri[i] = sum( y1^2 ) + sum( y2^2 )

This looks like a homework question.
FAQ: Homework Policy - meta / Guides & FAQs - RStudio Community

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.