Skip to content

Instantly share code, notes, and snippets.

@Aariq
Created September 17, 2024 16:53
Show Gist options
  • Save Aariq/b342d6567e9b53110006e717be226cd1 to your computer and use it in GitHub Desktop.
Save Aariq/b342d6567e9b53110006e717be226cd1 to your computer and use it in GitHub Desktop.
library(tidyverse)
#fake excedences data
excedences <- tribble(
~analyte, ~threshold,
"x", 0,
"y", 1
)
excedences
#fake analyte data
data_long <-
tibble(type = rep(c("A", "B"), 5), x = rnorm(10), y = rnorm(10)) |>
pivot_longer(c(x,y), names_to = "analyte")
data_long
excedences
full_join(data_long, excedences) |>
mutate(exceded = value > threshold) |>
group_by(type, analyte) |>
summarize(
mean = mean(value),
excecence_count = sum(exceded),
excedence_percent = sum(exceded)/n()*100
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment