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
It would be nice to support matrix_or_df.rx[1, 2] as an alternative to matrix_or_df.rx(1, 2). This would also let you assign to a matrix or data frame using matrix_or_df.rx[1, 2] = ....
As an extension, it would also be nice to support matrix_or_df.rx[:, 2] as an alternative to matrix_or_df.rx(True, 2), and matrix_or_df.rx[2, :] as an alternative to matrix_or_df.rx(2, True). Note that this would mean matrix_or_df.rx[2, :] would behave differently from matrix_or_df.rx[2], which is unexpected for Python but makes sense when you consider that matrix_or_df[2,] and matrix_or_df[2] are different in R.
The text was updated successfully, but these errors were encountered:
Wainberg
changed the title
Support matrix.rx[] indexing
Support .rx[row, col] indexing for matrices and data frames
Jan 28, 2024
Yes. I once considered it but the subseting operator [ in R can accept named arguments. The R documentation for [ has"
Usage:
x[i]
x[i, j, ... , drop = TRUE]
x[[i, exact = TRUE]]
x[[i, j, ..., exact = TRUE]]
x$name
getElement(object, name)
x[i] <- value
x[i, j, ...] <- value
x[[i]] <- value
x$name <- value
Python does not allow it. Adding a named argument to a [ call is a syntax error.
I checked this again and PEP-0472 could have resolved this but was ultimately rejected (https://peps.python.org/pep-0472/). Alternative methods propose a dictionary as an additional index to have named parameters. This could be a good solution.
It would be nice to support
matrix_or_df.rx[1, 2]
as an alternative tomatrix_or_df.rx(1, 2)
. This would also let you assign to a matrix or data frame usingmatrix_or_df.rx[1, 2] = ...
.As an extension, it would also be nice to support
matrix_or_df.rx[:, 2]
as an alternative tomatrix_or_df.rx(True, 2)
, andmatrix_or_df.rx[2, :]
as an alternative tomatrix_or_df.rx(2, True)
. Note that this would meanmatrix_or_df.rx[2, :]
would behave differently frommatrix_or_df.rx[2]
, which is unexpected for Python but makes sense when you consider thatmatrix_or_df[2,]
andmatrix_or_df[2]
are different in R.The text was updated successfully, but these errors were encountered: