- 自然数・整数
- 整数を表すのに'L'が使われる
- 整数と整数のように見えるものは異なる
- 数学としては整数は整数、整数らしきものは整数らしきもの
- 計算機の中でのその扱いは異なって来得る
>x <- pi * c(-1:1,10)
>as.integer(x)
[1] -3 0 3 31
> is.integer(1)
[1] FALSE
> is.integer(1L)
[1] TRUE
> is.wholenumber <- function(x, tol = .Machine$double.eps^0.5) abs(x - round(x)) < tol
> is.wholenumber(1)
[1] TRUE
> (x <- seq(1,5, by=0.5) )
[1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
> is.wholenumber( x )
[1] TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE
- 有理数は整数と整数の比、整数÷整数
- Rでは有理数近似、近似的に有理数化(整数の比にする)関数がある
> install.packages("MASS")
> library(MASS)
> zapsmall(solve(X, X/5))
[,1] [,2] [,3] [,4] [,5]
[1,] 0.2 0.0 0.0 0.0 0.0
[2,] 0.0 0.2 0.0 0.0 0.0
[3,] 0.0 0.0 0.2 0.0 0.0
[4,] 0.0 0.0 0.0 0.2 0.0
[5,] 0.0 0.0 0.0 0.0 0.2
> fractions(solve(X, X/5))
[,1] [,2] [,3] [,4] [,5]
[1,] 1/5 0 0 0 0
[2,] 0 1/5 0 0 0
[3,] 0 0 1/5 0 0
[4,] 0 0 0 1/5 0
[5,] 0 0 0 0 1/5
> fractions(solve(X, X/5)) + 1
[,1] [,2] [,3] [,4] [,5]
[1,] 6/5 1 1 1 1
[2,] 1 6/5 1 1 1
[3,] 1 1 6/5 1 1
[4,] 1 1 1 6/5 1
[5,] 1 1 1 1 6/5
> z<-complex(real=3,imaginary=2)
> Re(z)
[1] 3
> Im(z)
[1] 2
> Mod(z)
[1] 3.605551
z=x+iy = Mod(z) * cos(t)+i sin(t); t=Arg(z)
> Arg(z)
[1] 0.5880026
> Conj(z)
[1] 3-2i
> Conj(z)
[1] 3-2i
> sqrt(Re(z)^2+Im(z)^2)
[1] 3.605551
> Mod(z)*(cos(Arg(z))+complex(real=0,imaginary=1)*sin(Arg(z)))
[1] 3+2i
> exp(pi*complex(real=0,imaginary=1))
[1] -1+0i