Examples for 'bit64::table.integer64'


Cross Tabulation and Table Creation for integer64

Aliases: table.integer64

Keywords: category

### ** Examples

message("pure integer64 examples")
pure integer64 examples
x <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
y <- as.integer64(sample(c(rep(NA, 9), 1:9), 32, TRUE))
z <- sample(c(rep(NA, 9), letters), 32, TRUE)
table.integer64(x)
x
<NA>    2    4    6    7    8    9 
  19    2    3    2    3    1    2 
table.integer64(x, order="counts")
x
   8    6    9    2    7    4 <NA> 
   1    2    2    2    3    3   19 
table.integer64(x, y)
      y
x      <NA>  1  2  4  5  7  8  9
  <NA>   10  2  2  2  0  1  2  0
  2       1  0  1  0  0  0  0  0
  4       2  0  0  0  0  1  0  0
  6       0  0  0  0  1  1  0  0
  7       2  0  0  1  0  0  0  0
  8       1  0  0  0  0  0  0  0
  9       1  0  0  0  0  0  0  1
table.integer64(x, y, return="data.frame")
      x    y Freq
1  <NA> <NA>   10
2     2 <NA>    1
3     4 <NA>    2
4     7 <NA>    2
5     8 <NA>    1
6     9 <NA>    1
7  <NA>    1    2
8  <NA>    2    2
9     2    2    1
10 <NA>    4    2
11    7    4    1
12    6    5    1
13 <NA>    7    1
14    4    7    1
15    6    7    1
16 <NA>    8    2
17    9    9    1
message("via as.integer64.factor we can use 'table.integer64' also for factors")
via as.integer64.factor we can use 'table.integer64' also for factors
table.integer64(x, as.integer64(as.factor(z)))
      
x      <NA> 1 2 3 4 5 6 7 8 9 10 11 12 13
  <NA>    6 0 1 0 0 2 1 1 0 3  1  1  2  1
  2       1 0 0 0 0 0 0 0 0 0  1  0  0  0
  4       2 0 0 0 1 0 0 0 0 0  0  0  0  0
  6       2 0 0 0 0 0 0 0 0 0  0  0  0  0
  7       0 1 0 0 0 0 0 0 1 1  0  0  0  0
  8       0 0 0 1 0 0 0 0 0 0  0  0  0  0
  9       1 0 0 0 0 0 0 0 0 0  1  0  0  0
message("via as.factor.integer64 we can also use 'table' for integer64")
via as.factor.integer64 we can also use 'table' for integer64
table(x)
x
2 4 6 7 8 9 
2 3 2 3 1 2 
table(x, exclude=NULL)
x
<NA>    2    4    6    7    8    9 
  19    2    3    2    3    1    2 
table(x, z, exclude=NULL)
      z
x      a c e i k q r u v w x y z <NA>
  <NA> 0 1 0 0 2 1 1 0 3 1 1 2 1    6
  2    0 0 0 0 0 0 0 0 0 1 0 0 0    1
  4    0 0 0 1 0 0 0 0 0 0 0 0 0    2
  6    0 0 0 0 0 0 0 0 0 0 0 0 0    2
  7    1 0 0 0 0 0 0 1 1 0 0 0 0    0
  8    0 0 1 0 0 0 0 0 0 0 0 0 0    0
  9    0 0 0 0 0 0 0 0 0 1 0 0 0    1
## Don't show: 
 stopifnot(identical(table.integer64(as.integer64(c(1,1,2))), table(c(1,1,2))))
 stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
 message("the following works with three warnings due to coercion")
the following works with three warnings due to coercion
 stopifnot(identical(table.integer64(c(1,1,2)), table(c(1,1,2))))
Warning in table.integer64(c(1, 1, 2)): coercing first argument to integer64
 stopifnot(identical(table.integer64(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4))))
Warning in table.integer64(as.integer64(c(1, 1, 2)), c(3, 4, 4)): coercing
argument 2 to integer64
 stopifnot(identical(table.integer64(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
Warning in table.integer64(c(1, 1, 2), as.integer64(c(3, 4, 4))): coercing
argument 1 to integer64
 message("the following works because of as.factor.integer64")
the following works because of as.factor.integer64
 stopifnot(identical(table(as.integer64(c(1,1,2))), table(c(1,1,2))))
 stopifnot(identical(table(as.integer64(c(1,1,2)),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
 stopifnot(identical(table(as.integer64(c(1,1,2)),c(3,4,4)), table(c(1,1,2),c(3,4,4))))
 stopifnot(identical(table(c(1,1,2),as.integer64(c(3,4,4))), table(c(1,1,2),c(3,4,4))))
## End(Don't show)

[Package bit64 version 4.0.5 Index]