Hello,
I have a list of 17 tables containing precipitation data from CHIRPS and pluviometric stations.
The tables are organized as dates on the first column, simulated in the second, and observed in the third.
I want to create a for loop that calculates the hydroGOF::GOF metrics for all the tables.
for (i in 1:length(stations_files)){
station <- readxl::read_xlsx(stations_files[i])
gofstation <- gof(sim = station[, 2], obs = station[,3])
results[i] <- gofstation
}
Although I think I am passing the correct columns of simulated and observed data to the gof function, I keep getting the error:
Error in me.default(sim, obs, na.rm = na.rm) :
Invalid argument type: 'sim' & 'obs' have to be of class: c('integer', 'numeric', 'ts', 'zoo')
When I calculate the gof with a single table, I dont get the error regarding the class.
If you run the following loop, is the class of each column one of the allowed classes?
for (i in 1:length(stations_files)){
station <- readxl::read_xlsx(stations_files[i])
paste(stations_files[i], "Col2", class(station[[2]]), "Col3", class(station[[3]]))
}
for (i in 1:length(stations_files)){
station[i] <- read.csv(stations_files[i])
station[i] = station[i] (na.omit())
gofstation <- gof(sim = station[[2]], obs = station[[3]])
results[i] <- gofstation
}
And now the error is the following:
Error in stationi : attempt to apply non-function
In addition: Warning message:
In [<-.data.frame(*tmp*, i, value = list(Data = c("1981-01-01", :
provided 3 variables to replace 1 variables
The error I got:
Error in get(results[i]) : invalid first argument
In addition: Warning messages:
1: 'rNSE' can not be computed: some elements in 'obs' are zero !
2: 'rd' can not be computed: some elements in 'obs' are zero !
3: In results[i] <- gofstation :
number of items to replace is not a multiple of replacement length