I have a dataset with multiple stations, depths and concentration. I am trying to find the difference in depth (or the thickness) based on where the minimum concentration increases by 0.1
For example: At station 1, the maximum depth is 14m. There is a conc of 0.1 at 4m and it increases to 0.2 at 6m. But then it goes down again to 0.1 at 10m and stays that way till 12m before it increases. It increases only by 0.05 at 13m. At 14m, the concentration is increased by 0.1. So 14m is the deepest (or maximum depth) where the lowest conc is found. I need to find a way to fix my code to find that 14... (i.e. where concentration increases by 0.1). I can find the max depth for a given station and the minimum concentration.
This code gives me a column with maximum depth for each station (max_depth) and another column on what the minimum concentration is for each station (min_conc).
How do I find at what depth does the lowest concentration increase by 0.1?
Im trying to use 'which' max and min but I can't figure out the code.. How to use Dplyr's Summarize and which() to lookup min/max values
station <- c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4)
depth <- c(1, 2, 3, 6, 8, 9, 10, 11, 12, 13, 14, 1, 3, 4, 6, 8, 10, 11, 14, 1, 2, 4, 6, 8, 9, 10, 15, 18, 20, 1, 2, 4, 6, 8, 10, 11)
conc <- c(0.4, 0.4, 0.3, 0.1, 0.2, NA, 0.2, 0.1, 0.1, 0.1, 0.15, 0.2, 0.5, 0.4, 0.3, 0.6, 0.4, 0.2, 0.1, 0.2, 0.3, 0.2, 0.5, 0.5, 0.3, 0.2, 0.1, 0.2, 0.2, 0.2, 0.8, 0.6, 0.4, 0.3, 0.2, 0.3, 0.3)
df <- cbind(station, depth, conc)
(df <- as.data.frame(df))
(depth <- df %>%
group_by(station) %>%
summarize(
Max_depth=miss(max(depth)),
min_conc=miss(min(conc, na.rm=TRUE)),
press_depth = depth[tail(which(conc == min(conc, na.rm = TRUE)), 1)]))
when I try this instead:
press_depth = depth[tail(which(conc == min(conc > 0.1, na.rm = TRUE)), 1)])
I get an error: Column press_depth
must be length 1 (a summary value), not 0