Repeat Function on Multiple Variables

Hi, I have a dataset with three columns: stations, Year, and avg.

There are 19 stations, and five to six years per Year, and a value for each year.

I am trying to run the Mann Kendall trend test on each of the 19 stations, using the rkt function.

I starting writing the code, copying, then changing the name of the station 19 times. I am sure there is a more efficient way to do this with loop, or lappy? Could someone help me on this? I am still learning this R!

Thank you.

My code: ("Year" has to be numeric for this to run)

library(rkt)

###### 
tn_trend1 <-rkt(date=alachua.tn.wide$Year, 
         y=alachua.tn.wide$BLUCOPK)
#> Error in integer(n): object 'alachua.tn.wide' not found
tn_trend1
#> Error in eval(expr, envir, enclos): object 'tn_trend1' not found

Created on 2021-05-03 by the reprex package (v1.0.0)

My data:--just the first two stations, of five years

A tibble: 105 x 3

Groups: station [18]

station Year avg

1 ALACHCHAN 2014 0.925
2 ALACHCHAN 2015 1.97
3 ALACHCHAN 2016 1.5
4 ALACHCHAN 2017 2.3
5 ALACHCHAN 2018 1.15
6 BLUCOPK 2014 1.5
7 BLUCOPK 2015 1.5
8 BLUCOPK 2016 1.7
9 BLUCOPK 2017 1.95
10 BLUCOPK 2018 1.33