0

I am trying to assign ranks to an IBI, there is a condition for one attribute that requires me to assign the average of all other attributes when Alkalinity < 25 mg/L. Can I assign an existing vector/column of attribute score means? I've tried the code below to first assign the mean for each (but I'm not sure this is correct)

    WWMBIscores <- WWMBI[c(1:126) , c(29, 33, 35, 37, 39, 41, 43)]
ScoreMeans <- rowMeans(WWMBIscores)

This code should then assign the value from "ScoreMeans" as the rank when alkalinity is less than 25 mg/L

Mollusca_IBI <-
  WWMBI %>%
  mutate(
    Mollusca_Abund = case_when(
      Alkalinity <= 5 ~ ScoreMeans,
      Mollusca_Abund <= 1 ~ 0 ,
      Mollusca_Abund >= 1 & Mollusca_Abund <= 9  ~ 1 ,
      Mollusca_Abund >= 9 &  Mollusca_Abund <=  99 ~ 3 ,
      Mollusca_Abund >= 99 ~ 5
    )
  ) %>% select(Mollusca_Abund)

It doesn't appear to be assigning means, but rather 0s as the value. I've included a small subset of the 7 ranks I have calculated, assume some of those are for areas where alkalinity is <25.

structure(list(MargDI_IBI = c(1, 1, 1, 3, 3), Pleid_IBI = c(1,  0, 0, 5, 1), Corixid_IBI = c(2, 0, 2, 0, 2), Trichop_IBI = c(0,  0, 0, 0, 0), Stratio_IBI = c(0, 0, 0, 0, 0), NonInsect_IBI = c(1,  0, 3, 3, 1), Insect_IBI = c(1, 1, 1, 3, 3)), row.names = c(NA, 
-5L), class = c("tbl_df", "tbl", "data.frame"))
  • 1
    Please add some example data to your question, that will make it easier for other users to help you. Look here to learn how to create a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Till Feb 09 '22 at 20:48
  • In this case you can edit your question to add the result of `dput(WWMBI)` or a subset thereof if it's a large dataset using `dput(head(WWMBI))` – Dan Adams Feb 09 '22 at 21:04
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Feb 13 '22 at 07:03

0 Answers0