Sum of rows based on time range
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
What I am trying to do is sum rows for every 10 days consecutive days. The problem that I have is in my dataframe, is that I have so many missed days, and by applying a function that will sum every 10 rows, it will not be practical as it can sum non-consecutive days. So I am looking for a solution to sum only every 10 consecutive days.
Regards,
0 comentarios
Respuestas (1)
Star Strider
el 24 de Jun. de 2022
Try something like this —
T1 = table(datetime('now') + days(sort(randperm(150, 20)))', randi(99,20,1), 'VariableNames',{'Time','Random'});
TT1 = table2timetable(T1)
TT1r = retime(TT1, 'regular', 'sum', 'TimeStep',days(10))
Here, there are two 10-day intervals in which there are no entries.
.
2 comentarios
Star Strider
el 24 de Jun. de 2022
My pleasure.
That is incorrect.
The MATLAB date and time functions are remarkably robust. They do not take into account individual months with respect to the edges of the intervals for summation (in this instance). Here, the code sums over every 10 consecutive days as instructed, regardless of the days of the month. See the retime documentation for details.
.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!