Integer, L, double, numeric
in R, integers can be setup using as.integer(x) or 1000L (L means L, long, because it used 32 bits representation of number which was longer than the old 8 or 16 bits !).
f <- integer(length) creates a vector of size length with only 0.
> f <- integer(1)
> f
[1] 0
> is.integer(f)
[1] TRUE
> identical(f, 0L)
[1] TRUE
The double() or numeric() are the same number representation:
real() for R <3.0.0 was the same but is deprecated.
microbenchmark(
1L:2000L
, 1:1000
, as.integer(1):as.integer(2000)
, times = 1000000L
)
Unit: nanoseconds
expr min lq mean median uq max
1L:2000L 129 144 181.2866 147 153 64915
1:1000 126 147 203.7078 149 154 20499610
as.integer(1):as.integer(2000) 299 329 453.9530 335 350 32912817
f <- integer(length) creates a vector of size length with only 0.
> f <- integer(1)
> f
[1] 0
> is.integer(f)
[1] TRUE
> identical(f, 0L)
[1] TRUE
The double() or numeric() are the same number representation:
real() for R <3.0.0 was the same but is deprecated.
microbenchmark(
1L:2000L
, 1:1000
, as.integer(1):as.integer(2000)
, times = 1000000L
)
Unit: nanoseconds
expr min lq mean median uq max
1L:2000L 129 144 181.2866 147 153 64915
1:1000 126 147 203.7078 149 154 20499610
as.integer(1):as.integer(2000) 299 329 453.9530 335 350 32912817
Commentaires
Enregistrer un commentaire