Hello everybodey
I have a dataset with snow depth measurements modelled hourly. I would like to get a vector with the values of the distance per hour from the lowest and the highest snow depth. I have tried to write a function for this. The function is accepted by R when I use as.Date. However, I cannot display the hour information in as.Data. When using the command as.POSIXlt I get as error message:
Error in while (Date <= E) { : missing value where TRUE/FALSE needed
In addition: Warning message:
All formats failed to parse. No formats found.
I hope someone can help me here. Many greetings
my current R-code
#x = Range of values of the modelled snow depth curves; $timestamp = Date of the modelled snow height; $value = modelled Snow height
Distancevector <- function (Beginn, End, x) {
Date = as.POSIXlt(Beginn,format ="%Y-%m-%d %H:%M:%S")
Distances <- 1
i <- 1
E <- ymd_hms(End)+ hours(25)
E <- as.POSIXlt(E,format ="%Y-%m-%d %H:%M:%S")
while (Date<=E){
minmax <- range(x$value[x$timestamp==Datum])
Distance <- minmax [2] - minimax [1]
Distances[i] <- Distance
i <- i + 1
Date <- ymd_hms(Date) + hours(1)
Date <- as.POSIXlt(Date,format ="%Y-%m-%d %H:%M:%S")
}
return(Distances)
print(Distances)
}
DistancesV <- Distancevector(Beginn="2020-12-20 01:00:00", End="2021-01-11 01:00:00", x=test)