Skip to content
Prev 392789 / 398502 Next

apply to row and column of matrix

Bert provided an excellent answer to your question.
FYI here is a different approach to do the calculation.
It uses data.frame rather than matrix. A data frame is a list of its columns.
Here the function supplied to sapply operates on each column of the data.frame.
V1  V2  V3  V4  V5
1   1     2    3     4    5
2    6    7    8     9   10
V1  V2  V3  V4  V5
[1,]    1     2    3     4    5
[2,]    7     9   11   13  15
On Mon, Sep 26, 2022 at 5:57 PM Bert Gunter <bgunter.4567 at gmail.com> wrote: