0

I currently have a data set with mercury in fish levels (as values). I wanted to add another column classifying the concentration as "low" "medium" or "high", based on a value I would determine. Ex:<0.1 is considered low, between 0.1 and 0.3 is medium and >0.3 is high.

enter image description here

I honestly dont know where to start with coding this. I was thinking of using an if function.

Reb
  • 1

1 Answers1

0

Hey try using the case_when function from dplyr. Example below:

library(tidyverse)

data_categories <- 
  data |> 
  mutate(conc_cats = case_when(conc < 0.1 ~ "Low", 
                               conc > 0.1 & conc < 0.3 ~ "Medium", 
                               conc > 0.3 ~ "High"))