table.integer64
uses the cross-classifying integer64 vectors to build a
contingency table of the counts at each combination of vector values.
Arguments
- ...
one or more objects which can be interpreted as factors (including character strings), or a list (or data frame) whose components can be so interpreted. (For
as.table
andas.data.frame
, arguments passed to specific methods.)- return
choose the return format, see details
- order
By default results are created sorted by "values", or by "counts"
- nunique
NULL or the number of unique values of table (including NA). Providing
nunique
can speed-up matching whentable
has no cache. Note that a wrongnunique
can cause undefined behaviour up to a crash.- method
NULL for automatic method selection or a suitable low-level method, see details
- dnn
the names to be given to the dimensions in the result (the dimnames names).
- deparse.level
controls how the default
dnn
is constructed. See Details.
Value
By default (with return="table"
) table()
returns a
contingency table, an object of class "table"
, an array of integer values.
Note that unlike S the result is always an array, a 1D array if one factor is
given. Note also that for multidimensional arrays this is a dense return
structure which can dramatically increase RAM requirements (for large arrays
with high mutual information, i.e. many possible input combinations of which
only few occur) and that table()
is limited to 2^31
possible combinations
(e.g. two input vectors with 46340 unique values only). Finally note that the
tabulated values or value-combinations are represented as dimnames
and that
the implied conversion of values to strings can cause severe performance
problems since each string needs to be integrated into R's global string cache.
You can use the other return=
options to cope with these problems, the potential
combination limit is increased from 2^31
to 2^63
with these options, RAM is
only required for observed combinations and string conversion is avoided.
With return="data.frame"
you get a dense representation as a data.frame()
(like that resulting from as.data.frame(table(...))
) where only observed
combinations are listed (each as a data.frame row) with the corresponding
frequency counts (the latter as component named by responseName
). This is
the inverse of xtabs()
.
With return="list"
you also get a dense representation as a simple
list()
with components
values
a integer64 vector of the technically tabulated values, for 1D this is the tabulated values themselves, for kD these are the values representing the potential combinations of input valuescounts
the frequency countsdims
only for kD: a list with the vectors of the unique values of the input dimensions
Details
This function automatically chooses from several low-level functions considering
the size of x
and the availability of a cache.
Suitable methods are
hashmaptab
(simultaneously creating and using a hashmap)hashtab
(first creating a hashmap then using it)sortordertab
(fast ordering)ordertab
(memory saving ordering).
If the argument dnn
is not supplied, the internal function
list.names
is called to compute the 'dimname names'. If the
arguments in ...
are named, those names are used. For the
remaining arguments, deparse.level = 0
gives an empty name,
deparse.level = 1
uses the supplied argument if it is a symbol,
and deparse.level = 2
will deparse the argument.
Arguments exclude
, useNA
, are not supported, i.e. NA
s are always tabulated,
and, different from table()
they are sorted first if order="values"
.
Note
Note that by using as.integer64.factor()
we can also input
factors into table.integer64
– only the levels()
get lost.
See also
table()
for more info on the standard version coping with Base R's
data types, tabulate()
which can faster tabulate integer
s with a limited
range [1L .. nL not too big]
, unique.integer64()
for the unique values
without counting them and unipos.integer64()
for the positions of the unique values.
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> 1 3 4 5 6 8 9
#> 18 1 5 2 2 1 1 2
table.integer64(x, order="counts")
#> x
#> 8 6 1 9 5 4 3 <NA>
#> 1 1 1 2 2 2 5 18
table.integer64(x, y)
#> y
#> x <NA> 1 2 3 6 7 9
#> <NA> 8 1 1 1 1 2 4
#> 1 0 0 1 0 0 0 0
#> 3 4 0 0 0 1 0 0
#> 4 2 0 0 0 0 0 0
#> 5 1 0 0 0 1 0 0
#> 6 0 0 1 0 0 0 0
#> 8 0 1 0 0 0 0 0
#> 9 0 0 0 0 0 1 1
table.integer64(x, y, return="data.frame")
#> x y Freq
#> 1 <NA> <NA> 8
#> 2 3 <NA> 4
#> 3 4 <NA> 2
#> 4 5 <NA> 1
#> 5 <NA> 1 1
#> 6 8 1 1
#> 7 <NA> 2 1
#> 8 1 2 1
#> 9 6 2 1
#> 10 <NA> 3 1
#> 11 <NA> 6 1
#> 12 3 6 1
#> 13 5 6 1
#> 14 <NA> 7 2
#> 15 9 7 1
#> 16 <NA> 9 4
#> 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 14 15 16 17
#> <NA> 2 2 0 0 2 1 1 1 0 1 2 1 1 0 2 1 1 0
#> 1 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0
#> 3 1 1 1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0
#> 4 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0
#> 5 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0 0 0
#> 6 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> 8 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
#> 9 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1