Hi:
On 6/7/21 11:44 AM, Enrico Gabrielli wrote:
Hello
I'm looking at if and how to find support with paid computer scientists
because it is not possible for an agricultural technician in the midst
of activities in the field, who does not know how to use R
solve this problem also through a mailing-list.
However it is right to complete the description of the problem, maybe
you have ideas that I will give to the computer scientists that we will
pay with the project
so I am not asking here for the solution, but only for ideas.
This is an data example (really)
datetime capture
2021-05-15 14:09:00 15
2021-05-16 10:34:00 2
2021-05-20 15:00:00 3
2021-05-23 08:30:00 23
2021-05-29 07:30:00 30
2021-05-29 19:00:00 25
2021-06-01 19:00:00 23
2021-06-05 12:52:00 92
2021-06-05 19:00:00 5
This is the results of two possibile solution
week simple SUM week right SUM week
19 17 19,44027778
20 26 52,91388889
21 55 46,4375
22 120 99,20833333
simple is done with a simple sum by aggregate with weeknum
right is done with a it is done with the calculation of the ratio
between catches and time interval
It's still not clear. time interval in hours? or days?
Have a look at this code, using your example data:
library(dplyr)
Hh <- read.table(header = FALSE, text="2021-05-15 14:09:00 15
2021-05-16 10:34:00 2
2021-05-20 15:00:00 3
2021-05-23 08:30:00 23
2021-05-29 07:30:00 30
2021-05-29 19:00:00 25
2021-06-01 19:00:00 23
2021-06-05 12:52:00 92
2021-06-05 19:00:00 5")
colnames(Hh) <- c("Date", "Time", "Captures")
Hh$DateTime <- as.POSIXct(paste(Hh$Date, Hh$Time),
format = "%Y-%m-%d %H:%M:%S",
tz = "UTC") # What time zone??
# I assume time interval in days
# The first row must have timediff=0, since there is no previous DateTime
Hh$Timediff <- c(0, diff(Hh$DateTime)/24)
# Captures per hour
Hh$Capt.per.Day <- ifelse(Hh$Timediff == 0, 0, Hh$Captures/Hh$Timediff)
# Week number:
Hh$Weeknum <- strftime(Hh$DateTime, "%Y%W")
Hh
Date Time Captures DateTime Timediff
Capt.per.Day Weeknum
1 2021-05-15 14:09:00 15 2021-05-15 14:09:00 0.0000000 0.0000000
202119
2 2021-05-16 10:34:00 2 2021-05-16 10:34:00 0.8506944 2.3510204
202119
3 2021-05-20 15:00:00 3 2021-05-20 15:00:00 4.1847222 0.7168935
202120
4 2021-05-23 08:30:00 23 2021-05-23 08:30:00 2.7291667 8.4274809
202120
5 2021-05-29 07:30:00 30 2021-05-29 07:30:00 5.9583333 5.0349650
202121
6 2021-05-29 19:00:00 25 2021-05-29 19:00:00 0.4791667 52.1739130
202121
7 2021-06-01 19:00:00 23 2021-06-01 19:00:00 3.0000000 7.6666667
202122
8 2021-06-05 12:52:00 92 2021-06-05 12:52:00 3.7444444 24.5697329
202122
9 2021-06-05 19:00:00 5 2021-06-05 19:00:00 0.2555556 19.5652174
202122
# Now sum by wekknum
Hh_weekly <- Hh %>%
group_by(Weeknum) %>%
summarise(Hourly.Capt.per.Week = sum(Capt.per.Day)) %>%
ungroup()
Hh_weekly
# A tibble: 4 x 2
Weeknum Hourly.Capt.per.Week
<chr> <dbl>
1 202119 2.35
2 202120 9.14
3 202121 57.2
4 202122 51.8
Does that bring you any closer??
but this is done with a spreadsheet, but in order to automate the
generation of an html graph on the project server page, I need to do
this with R
I tested the xts package, and then I found lubridate and padr
interesting, but I stopped due to lack of time
--
Micha Silver
Ben Gurion Univ.
Sde Boker, Remote Sensing Lab
cell: +972-523-665918
_______________________________________________
R-sig-ecology mailing list
R-sig-ecology@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-ecology