1
2

More than 3 years have passed since last update.

【初心者向け】Rからxtableを用いて掛け算九九表のHTMLを出力する。

Last updated at Posted at 2020-03-12

多くの人が腕試しに試みてるので私も挑戦してみました。

1x 2x 3x 4x 5x 6x 7x 8x 9x
1y 1 2 3 4 5 6 7 8 9
2y 2 4 6 8 10 12 14 16 18
3y 3 6 9 12 15 18 21 24 27
4y 4 8 12 16 20 24 28 32 36
5y 5 10 15 20 25 30 35 40 45
6y 6 12 18 24 30 36 42 48 54
7y 7 14 21 28 35 42 49 56 63
8y 8 16 24 32 40 48 56 64 72
9y 9 18 27 36 45 54 63 72 81
#各段の準備
Step1<-c(1:9)
Step2<-as.integer(Step1*2)
Step3<-as.integer(Step1*3)
Step4<-as.integer(Step1*4)
Step5<-as.integer(Step1*5)
Step6<-as.integer(Step1*6)
Step7<-as.integer(Step1*7)
Step8<-as.integer(Step1*8)
Step9<-as.integer(Step1*9)

#MT=Multiplication Table(九九の英訳)
MT<- data.frame(S1=Step1,S2=Step2,S3=Step3,S4=Step4,S5=Step5,S6=Step6,S7=Step7,S8=Step8,S9=Step9)

#段の名前設定
colnames(MT)<-c("1x","2x","3x","4x","5x","6x","7x","8x","9x")
rownames(MT)<-c("1y","2y","3y","4y","5y","6y","7y","8y","9y")

#HTML出力
library(xtable)
print(xtable(MT),type="html")

型変換が必要なのが盲点でした…まぁ、普段はあまり意識しませんからね。
ナウい言語は暗黙の整数拡張を行わないか?

ちなみに「九九を巡る数理」は案外深く、色々な展開が考えられたりします。
【Rで九九】どうして36個の数字しか使われないのか?

1
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2