Glad that helped. When I put on my phyto scientist hat, instead of my R-coder hat, I have one more related observation. The validity of the previous approach relies on you measuring the same relative maximum amount of turbidity with each of your instruments. That may, or may not, be a good assumption, depending on where and how they were deployed. If that is a concern, I suggest instead of the above approach, you check each instrument for its maximum value, or the value it get when reading a very turbid standard, and normalize to those readings. Then I think your use of the normalized turbidity readings in subsequent analyses would be more valid.
Below is another bit of code to use predefined values that you get from the maximum scale or maximum turbidity standard. I've used the example values I mentioned in my previous post. Note that if you want, you can drop the max_scale variable by piping the dataframe through select(-max_scale)
. That might give you a cleaner data set.
library(tidyverse)
df <- tribble(~values, ~unit, ~abundance,
0.5, "x", 500,
10, "x", 30,
50, "y", 50,
100, "y", 100,
30, "z", 20,
60, "z", 60,
500, "z", 80
)
scale_max <- c(15, 200, 1000) # Maximum possible in units of x, y and z, respectively
df_rescaled2 <- df %>%
mutate(max_scale = case_when(
unit == "x" ~ scale_max[1],
unit == "y" ~ scale_max[2],
unit == "z" ~ scale_max[3] ),
rescaled_values = values/max_scale)
df_rescaled2
#> # A tibble: 7 x 5
#> values unit abundance max_scale rescaled_values
#> <dbl> <chr> <dbl> <dbl> <dbl>
#> 1 0.5 x 500 15 0.0333
#> 2 10 x 30 15 0.667
#> 3 50 y 50 200 0.25
#> 4 100 y 100 200 0.5
#> 5 30 z 20 1000 0.03
#> 6 60 z 60 1000 0.06
#> 7 500 z 80 1000 0.5
Created on 2021-11-19 by the reprex package (v2.0.1)