Reputation: 2606
I'm getting strange behavior where matrix dimensions are not working as expected here is a toy example
n <- 10
delt <- 0.00001
s <- n/delt + 1
print(s)
s = 1000001
x <- matrix(0, nrow = s, ncol = 2)
dim(x)
1000000 2
However, if I type
x <- matrix(0, nrow = 1000001, ncol = 2)
dim(x)
I get what I expect 1000001 2
Upvotes: 1
Views: 29
Reputation: 35314
This is why:
print(s,digits=20L); ## s is slightly under 1000001 after all
## [1] 1000000.9999999998836
as.integer(s); ## truncates to 1000000
## [1] 1000000
The documentation on matrix()
doesn't explicitly say it, but the nrow
and ncol
arguments are internally coerced to integer.
Also see Why are these numbers not equal?.
Upvotes: 2