-
-
Notifications
You must be signed in to change notification settings - Fork 219
Description
The proposal here is to improve API consistency between the 2D classes Matrix
and DataFrame
by:
- deprecating the
.nrows()
function inDataFrame
in favor of adding.nrow()
and.rows()
- introduce the
.ncol()
and.cols()
functions toDataFrame
that map toVector
'ssize()
andlength()
functions.
However, another interesting proposal would be to remove the size attribute access information provided by .cols()
and .rows()
for the Matrix
class and introduce .Rows(first, last)
and .Cols(first, last)
that would provide submatrix views.
APIs
For the Matrix
class, the following member functions are defined for dimensional information:
Member | Description |
---|---|
.nrow() ,.rows() |
number of rows in a Matrix |
.ncol() ,.cols() |
number of columns in a Matrix |
.size() ,.length() |
number of items in a Matrix , Vector |
Meanwhile, over in DataFrame
land, the member functions are defined a bit differently:
Member | Description |
---|---|
.nrows() |
number of rows in a DataFrame |
.size() ,.length() |
number of columns in a DataFrame |
The break in consistency regarding the nrow()
and ncol()
within DataFrame
is problematic as it breaks with those accessor functions available in base R.
data.frame
and length()
note
Note, there is no need to change the length()
function call since the R equivalent returns the number of columns instead of the amount of elements, e.g.
df = data.frame(a = 1:3, b = 3:1)
length(df)
# 2