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
Sometimes I need to compute a matrix column-wise using a function.
Base-R code to achieve that would be vapply() with a FUN.VALUE of length greater than 1.
For a toy example with an easier solution consider this function:
If n > 1, this works as expected and returns a matrix of normal random variates with true column means means and constant standard deviation sd. However, the return type is not stable for n = 1 in which case the value will be a length length(means) vector instead of a 1-row matrix.
I propose a family of functions map_*_matrix() which always return a matrix and behaviour akin to
I think this is out of scope for purrr, since we don't currently have functions that return matrices and I don't think we want to increase the API size so much.
Sometimes I need to compute a matrix column-wise using a function.
Base-R code to achieve that would be
vapply()
with aFUN.VALUE
of length greater than 1.For a toy example with an easier solution consider this function:
If
n > 1
, this works as expected and returns a matrix of normal random variates with true column meansmeans
and constant standard deviationsd
. However, the return type is not stable forn = 1
in which case the value will be a lengthlength(means)
vector instead of a 1-row matrix.I propose a family of functions
map_*_matrix()
which always return a matrix and behaviour akin toMaybe additional convenience arguments such as
.byrow = FALSE
to decide whether to create the matrix rowwise or column-wise are necessary as well.If there is interest in such a feature, I'll gladly try to get a PR started, so please let me know.
The text was updated successfully, but these errors were encountered: