Sum of rows based on time range
조회 수: 5 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Star Strider
2022년 6월 24일
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
Star Strider
2022년 6월 24일
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.
.
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!