You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@jangorecki thank you for the comment and the link.
You seem to argue that zero-row/column matrices should be a thing and nonzero-row zero-column data.frames should not be a thing. I would tend to agree, however below is an example of scenario I encountered where such data.frames are a good default edge case.
For my personal uses I am developing an "annotated matrix" object. That is - a matrix with persistent annotations of rows and columns. This object holds annotation about rows and columns in two separate data.frames. Once you select the row of such a matrix - row annotations are automatically subsetted and vice-versa.
Under such conditions a data.frame with non zero rows and zero columns is quite useful - it's a state of there not being any meta-data present. So for a matrix with n rows and m columns - the column-annotation data.frame would have n rows and 0 columns.
I found that having this behaviour works well with various cbind, rbind, etc operations by default without resorting to hacks. And I would have to add some ad-hoc solutions in order to make dim(0, 0) work.
This is precisely the issue I encountered and reported here. When I cbind my special matrices - I can simply also do cbind on their annotations. However this didn't work when I did an rbind, which was confusing (but documented) behaviour in base R.
With
matrix
objectsrbind
works as expected:Once turned into
data.frame
s the rows are dropped:However
cbind
works as expected:The text was updated successfully, but these errors were encountered: