Skip to content

Mirror Matrix Dimensional Member Functions for DataFrame  #630

@coatless

Description

@coatless

The proposal here is to improve API consistency between the 2D classes Matrix and DataFrame by:

  1. deprecating the .nrows() function in DataFrame in favor of adding .nrow() and .rows()
  2. introduce the .ncol() and .cols() functions to DataFrame that map to Vector's size() and length() 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions