[R] rep with bigz in gmp

Kohske Takahashi takahashi.kohske at gmail.com
Wed Mar 28 06:03:08 CEST 2012


Hi

With package:gmp, is this an expected behavior?

> rep(1:3, rep(3, 3))
[1] 1 1 1 2 2 2 3 3 3

> rep(as.bigz(1:3), rep(3, 3))
Big Integer ('bigz') object of length 9:
[1] 1 2 3 1 2 3 1 2 3

This code is used inside `outer`, so more worse

> outer(1:3, 1:3, `*`)
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    6
[3,]    3    6    9

> outer(as.bigz(1:3), as.bigz(1:3), `*`)
Big Integer ('bigz') 3 x 3 matrix:
     [,1] [,2] [,3]
[1,] 1    1    1
[2,] 4    4    4
[3,] 9    9    9

of course, here is a workaround:

> outer(as.bigz(1:3), as.numeric(as.bigz(1:3)), `*`)
Big Integer ('bigz') 3 x 3 matrix:
     [,1] [,2] [,3]
[1,] 1    2    3
[2,] 2    4    6
[3,] 3    6    9

thanks in advance.

kohske

-- 
--
Kohske Takahashi <takahashi.kohske at gmail.com>

Research Center for Advanced Science and Technology,
The University of  Tokyo, Japan.
http://www.fennel.rcast.u-tokyo.ac.jp/profilee_ktakahashi.html



More information about the R-help mailing list