How to calculate McLoone Index?

Hi, and welcome!

The key to getting more and better answer lies in the FAQ: What's a reproducible example (`reprex`) and how do I do one?

For your problem, at a minimum it should look like

dat <- c(1000,1000,200,200,200,200,100,100,100,100,100,100,60,60,60,60,60,60,45,45,45,45,45,45,45,45,12,24,12,24,12,24,12,24,12,24,12,24,12,24,12,24,12,24,12,24,12,24,12,24)

Created on 2020-02-13 by the reprex package (v0.3.0)

and, ideally, what you have tried.

Also, if applicable, see FAQ: Homework Policy

So, to start you need the median.

med <- median(dat)

Next, you need to subset for all observations below the median (assuming that you don't be at or below the median).

lower <- dat[dat < med]

The sum is easy enough

tot <- sum(lower)

as is the number of observations

obs <- length * tot

And with that, the + operator will give you a final result.

1 Like