Skip to contents

Convert output from classify() to matrix/data.frame/data.table

Usage

# S3 method for classified
as.data.frame(x, ...)

# S3 method for classified
as.data.table(x, ...)

# S3 method for classified
as.matrix(x, ...)

Arguments

x

output from classify()

...

ignored

Value

data frame/data table with:

  • first column named as "id" column specified as input to classify() and with data from row.names(x)

  • all columns from classified

  • no row names

or simply the input matrix without additional attributes

Examples

x <- classify(c("C80", "I20", "unvalid_code"), "elixhauser")
#> Classification based on: icd10

as.matrix(x)[, 1:3]
#>              congestive heart failure cardiac arrhythmias valvular disease
#> C80                             FALSE               FALSE            FALSE
#> I20                             FALSE               FALSE            FALSE
#> unvalid_code                    FALSE               FALSE            FALSE
as.data.frame(x)[, 1:3]
#>             id congestive heart failure cardiac arrhythmias
#> 1          C80                    FALSE               FALSE
#> 2          I20                    FALSE               FALSE
#> 3 unvalid_code                    FALSE               FALSE
data.table::as.data.table(x)[, 1:3]
#>              id congestive heart failure cardiac arrhythmias
#> 1:          C80                    FALSE               FALSE
#> 2:          I20                    FALSE               FALSE
#> 3: unvalid_code                    FALSE               FALSE

# `as_tibble()` works automatically due to internal use of `as.data.frame()`.
tibble::as_tibble(x)
#> # A tibble: 3 × 31
#>   congestive h…¹ cardi…² valvu…³ pulmo…⁴ perip…⁵ hyper…⁶ hyper…⁷ paral…⁸ other…⁹
#>   <classifd>     <class> <class> <class> <class> <class> <class> <class> <class>
#> 1 FALSE          FALSE   FALSE   FALSE   FALSE   FALSE   FALSE   FALSE   FALSE  
#> 2 FALSE          FALSE   FALSE   FALSE   FALSE   FALSE   FALSE   FALSE   FALSE  
#> 3 FALSE          FALSE   FALSE   FALSE   FALSE   FALSE   FALSE   FALSE   FALSE  
#> # … with 22 more variables: `chronic pulmonary disease` <classifd>,
#> #   `diabetes uncomplicated` <classifd>, `diabetes complicated` <classifd>,
#> #   hypothyroidism <classifd>, `renal failure` <classifd>,
#> #   `liver disease` <classifd>, `peptic ulcer disease` <classifd>,
#> #   `AIDS/HIV` <classifd>, lymphoma <classifd>, `metastatic cancer` <classifd>,
#> #   `solid tumor` <classifd>, `rheumatoid arthritis` <classifd>,
#> #   coagulopathy <classifd>, obesity <classifd>, `weight loss` <classifd>, …