Hello, I have a function that I would like to run on a dataframe containing multiple factors. I have a flow from three sites (A,B,C). I simply want to run this function ("RBFlash") that provides an index of the flashiness of the flow.
I could make the data wide, and run the function separately on each site, but I think I can do it with sapply, but I keep throwing an error.
Can someone provide help on this? Thank you.
Data:
datapasta::tribble_paste(data.Q2)
#> Error in is.data.frame(input_table): object 'data.Q2' not found
tibble::tribble(
~site, ~flow,
"A", 6L,
"A", 2L,
"A", 4L,
"A", 6L,
"A", 7L,
"A", 4L,
"A", 6L,
"A", 5L,
"A", 8L,
"B", 23L,
"B", 26L,
"B", 33L,
"B", 34L,
"B", 24L,
"B", 50L,
"B", 45L,
"B", 29L,
"B", 30L,
"B", 42L,
"C", 86L,
"C", 114L,
"C", 230L,
"C", 173L,
"C", 187L,
"C", 88L,
"C", 206L,
"C", 168L,
"C", 153L,
"C", 86L
)
#> # A tibble: 29 × 2
#> site flow
#> <chr> <int>
#> 1 A 6
#> 2 A 2
#> 3 A 4
#> 4 A 6
#> 5 A 7
#> 6 A 4
#> 7 A 6
#> 8 A 5
#> 9 A 8
#> 10 B 23
#> # … with 19 more rows
Created on 2022-10-30 by the reprex package (v2.0.1)
R-script:
install.packages("remotes")
remotes::install_github("mccreigh/rwrfhydro")
#> Skipping install of 'rwrfhydro' from a github remote, the SHA1 (f6e03a41) has not changed since last install.
#> Use `force = TRUE` to force installation
library("rwrfhydro")
#> To check rwrfhydro updates run: CheckForUpdates()
RBI <- RBFlash(data.Q2$flow, na.rm = TRUE)
#> Error in diff(m): object 'data.Q2' not found
RBI.all <- sapply(data.Q2$flow, RBFlash, na.rm = TRUE)
#> Error in lapply(X = X, FUN = FUN, ...): object 'dataQ2' not found
Created on 2022-10-30 by the reprex package (v2.0.1)