Learn R Programming

tabula (version 1.3.0)

coerce: Coerce

Description

Coerce

Usage

as_count(from)

as_frequency(from)

as_incidence(from)

as_occurrence(from)

as_similarity(from)

# S4 method for ANY as_count(from)

# S4 method for ANY as_frequency(from)

# S4 method for ANY as_incidence(from)

# S4 method for ANY as_occurrence(from)

# S4 method for ANY as_similarity(from)

Arguments

from

A numeric matrix or data.frame to be coerced.

Value

A '>CountMatrix or an '>IncidenceMatrix.

Details

The following methods coerce a matrix or data.frame to a *Matrix object:

Method Target
as_count '>CountMatrix
as_frequency '>FrequencyMatrix
as_incidence '>IncidenceMatrix
as_occurrence '>OccurrenceMatrix

Examples

Run this code
# NOT RUN {
## Create a count matrix
A1 <- CountMatrix(data = sample(0:10, 100, TRUE),
                  nrow = 10, ncol = 10)

## Coerce counts to frequencies
B <- as_frequency(A1)

## Row sums are internally stored before coercing to a frequency matrix
## (use totals() to get these values)
## This allows to restore the source data
A2 <- as_count(B)
all(A1 == A2)

## Coerce to presence/absence
C <- as_incidence(A1)

## Coerce to a co-occurrence matrix
D <- as_occurrence(A1)
# }

Run the code above in your browser using DataLab