r - bigz variable type from package gmp with ifelse() -
why following return error?
> x <- as.bigz(5) > y <- ifelse(1,x,0) error in ifelse(1, x, 0) : incompatible types (from raw logical) in subassignment type fix
i can around doing
> x <- as.bigz(5) > y <- as.bigz(ifelse(1,as.character(x),0))
it seems have fact that
> as.raw(5) [1] 05
but
> as.raw(as.bigz(5)) [1] 01 00 00 00 01 00 00 00 01 00 00 00 05 00 00 00
which suggests ifelse() doing "as.raw" automatically. still though, if
> y <- as.raw(as.bigz(5)) > y [1] 01 00 00 00 01 00 00 00 01 00 00 00 05 00 00 00
is possible, difference?
basically means there no ifelse.bigz
method defined. base::ifelse
doesn't understand bigz
objects.
instead, use if ... else
, since if(bigz_x [relationship operator] bigz_y)
work because relationship operators have bigz
methods, returning logical value if
can work with.
rgames> if(1) x else 0 big integer ('bigz') : [1] 5
Comments
Post a Comment