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"))