Counts by columns (or rows) the number of each unique element of a FBM.code256.

big_counts(
  X.code,
  ind.row = rows_along(X.code),
  ind.col = cols_along(X.code),
  byrow = FALSE
)

Arguments

X.code

An object of class FBM.code256.

ind.row

An optional vector of the row indices that are used. If not specified, all rows are used. Don't use negative indices.

ind.col

An optional vector of the column indices that are used. If not specified, all columns are used. Don't use negative indices.

byrow

Count by rows rather than by columns? Default is FALSE (count by columns).

Value

A matrix of counts of K x m (or n) elements, where

  • K is the number of unique elements of the BM.code,

  • n is its number of rows,

  • m is its number of columns.

Beware that K is up to 256. So, if you apply this on a Filebacked Big Matrix of one million columns, you will create a matrix of nearly 1GB!

Examples

X <- big_attachExtdata() class(X) # big_counts() is available for class FBM.code256 only
#> [1] "FBM.code256" #> attr(,"package") #> [1] "bigstatsr"
X[1:5, 1:8]
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #> [1,] 2 2 0 2 1 1 2 0 #> [2,] 1 2 1 2 2 1 2 0 #> [3,] 2 1 1 2 0 1 2 0 #> [4,] 2 2 0 2 0 1 2 0 #> [5,] 1 2 2 2 0 0 1 2
# by columns big_counts(X, ind.row = 1:5, ind.col = 1:8)
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] #> 0 0 0 2 0 3 1 0 4 #> 1 2 1 2 0 1 4 1 0 #> 2 3 4 1 5 1 0 4 1 #> <NA> 0 0 0 0 0 0 0 0
# by rows big_counts(X, ind.row = 1:5, ind.col = 1:8, byrow = TRUE)
#> [,1] [,2] [,3] [,4] [,5] #> 0 2 1 2 3 2 #> 1 2 3 3 1 2 #> 2 4 4 3 4 4 #> <NA> 0 0 0 0 0