Print a multiplication table with minimal code

后端 未结 2 737
再見小時候
再見小時候 2020-12-20 07:42

In R, what is the fastest way(shortest code) to print multiplication table? The functions seq rep and the bind functions help, but I\'m looking for the shortest line(s) of c

2条回答
  •  别那么骄傲
    2020-12-20 08:26

    A shortcut for outer(1:6, 1:12, "*"):

    > 1:6 %o% 1:12
         [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12]
    [1,]    1    2    3    4    5    6    7    8    9    10    11    12
    [2,]    2    4    6    8   10   12   14   16   18    20    22    24
    [3,]    3    6    9   12   15   18   21   24   27    30    33    36
    [4,]    4    8   12   16   20   24   28   32   36    40    44    48
    [5,]    5   10   15   20   25   30   35   40   45    50    55    60
    [6,]    6   12   18   24   30   36   42   48   54    60    66    72
    

提交回复
热议问题