Repository navigation
crosstab, tabulate: accept datetime and duration inputs - #525
Merged
pr0m1th3as merged 1 commit intoOct 17, 2026
Merged
Conversation
Datetime and duration vectors are grouped through grp2idx, in sorted order, and missing values (NaT, NaN) are not counted. The results match MATLAB R2026b.
pr0m1th3as
added a commit
that referenced
this pull request
Oct 17, 2026
…w-up to #525 * inst/Data_Manipulation/grp2idx.m: Document that a NaN duration is missing and that MATLAB makes it a group of its own. * inst/Data_Manipulation/crosstab.m: Likewise. Write each numeric label on its own, so none is padded and an empty input has none. Convert numeric input to double, so an integer type beside other numbers no longer raises an error. Add tests. * inst/Descriptive_Statistics/tabulate.m: Document that a NaN duration is missing and the empty table for an all-missing datetime or duration vector. Handle datetime and duration in the branch for strings. Add a test.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #522.
crosstabandtabulaterefused datetime and duration vectors with their own type checks before reachinggrp2idx, while MATLAB accepts both in both functions.Changes
grp2idx, so labels are the group names and missing values (NaT, NaN) are not counted. A datetime or duration matrix is refused with the existing "must be vectors" error.ismissingand numbers the groups withgrp2idx, in sorted order, returning the same 3-column cell table as the other non-numeric types.tabulatealso states that NaT and NaN durations are ignored and that the values are sorted.Comparison with MATLAB R2026b
Data: three dates repeated six times with one NaT, against 1, 2 and 3 hours.
[t, chi2, p, labels] = crosstab (d, h)t = [0 6 0; 5 0 0; 0 0 6],chi2 = 34,p = 7.4519e-07, labels'01-Mar-2025'... and'1 hr'...tabulate (d)6, 5, 6, percents35.2941, 29.4118, 35.2941(NaT left out of the total)tabulate (h)'1 hr','2 hr','3 hr', counts6, 6, 6, percents33.3333Testing
Octave 11.3.0, datatypes 1.5.0:
crosstab: 34 of 34 pass, 3 tests new.tabulate: 35 of 35 pass, 9 tests new. Edge cases cover a NaN duration, row input, all-NaT and empty input, printed output, and matrix input.grp2idxandknnsearch(the other caller ofcrosstab) still pass.Not included
Other functions where MATLAB R2026b refuses datetime are left alone:
dummyvar,mnrfit, andfitctree/TreeBagger/fitcensemble.