Hopefully a graphic representation of what is happening....
2614 * 1456000
#[1] 3805984000
## Integers are actually represented as doubles
class( 2614 * 1456000 )
#[1] "numeric"
# Force numbers to be integers
2614L * 1456000L
#[1] NA
#Warning message:
#In 2614L * 1456000L : NAs produced by integer overflow
## And the result is an integer with overflow warning
class( 2614L * 1456000L )
#[1] "integer"
#Warning message:
#In 2614L * 1456000L : NAs produced by integer overflow
2614 * 1456000
is a numeric
because both the operands are actually of class numeric
. The overflow occurs because both nrow
and length
return integer
's and hence the result is an integer but the result exceeds the maximum size representable by the integer
class (+/-2*10^9). A numeric
or double
can hold 2e-308 to 2e+308
. So to solve your problem, just use as.numeric(length(A))
or as.double(length(A))
.