Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating composite score data #4

Open
hadley opened this issue Aug 3, 2015 · 2 comments
Open

Creating composite score data #4

hadley opened this issue Aug 3, 2015 · 2 comments

Comments

@hadley
Copy link

hadley commented Aug 3, 2015

I think this could be simplified quite a bit with a couple of functions like

rescale01 <- function(x) {
  rng <- range(x, na.rm = TRUE)
  (x - rng[1]) / (rng[2] - rng[1])
}

composite_score <- function(x, wt) {
   x <- rescale01(x)
   x <- x[!is.na(x)]

  mean(wt * x)
}

(I think that's what you're doing, but I'm not absolutely sure)

@hadley
Copy link
Author

hadley commented Aug 3, 2015

Similarly, when computing indexes, it would be a good idea to reduce some of the duplication with a function.

@aloy
Copy link
Contributor

aloy commented Aug 11, 2015

I pared down the code using your suggestion for rescale01 along with the weighted.mean function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants