Repeat function on dataframe with multiple factors--sapply?

@FactOREO ---Thank you so much!!! It worked perfect. I need to dig in to figure out when to use tapply versus sapply!

@FactOREO I am trying to run a similar script, with a different dataset and function, and keep getting an error thrown at me. Do you have any ideas? Thank you.

A little bit of the data:

tibble::tribble(
                              ~date.well.combined2.parm.code.....adj,
                     "1 2008-10-09           MW01       nox  0.0075",
                     "2 2008-10-09           MW07       nox  1.7000",
                     "3 2008-10-10           MW11       nox  4.6000",
                     "4 2008-10-10           MW22       nox  0.1900",
                     "5 2008-10-10           SW01       nox  1.4000",
                     "6 2008-10-21           MW04       nox 12.0000"
                                                     
                     )
#> # A tibble: 6 × 1
#>   date.well.combined2.parm.code.....adj        
#>   <chr>                                        
#> 1 1 2008-10-09           MW01       nox  0.0075
#> 2 2 2008-10-09           MW07       nox  1.7000
#> 3 3 2008-10-10           MW11       nox  4.6000
#> 4 4 2008-10-10           MW22       nox  0.1900
#> 5 5 2008-10-10           SW01       nox  1.4000
#> 6 6 2008-10-21           MW04       nox 12.0000

Created on 2022-11-07 by the reprex package (v2.0.1)

I tried running the script two ways: one using "goup_by" and the other your "tapply" method:

outliers.grubb <- high %>%
  group_by(well.combined2) %>%
    sapply(adj, grubbs.test, na.rm = T
                        )
#> Error in high %>% group_by(well.combined2) %>% sapply(adj, grubbs.test, : could not find function "%>%"

outliers.grubb <- tapply(high$well.combined2, high$adj, grubbs.test, na.rm =T)
#> Error in tapply(high$well.combined2, high$adj, grubbs.test, na.rm = T): object 'grubbs.test' not found

Created on 2022-11-07 by the reprex package (v2.0.1)