numerical: Convert a fractional object to the equivalent numeric object

Description Usage Arguments Value Methods (by class) Examples

View source: R/fractionl.R

Description

Convert an object of class "fractional" or "charFrac" to a purely numeric object. This is effectively a method function for the .Primitive generic function as.numeric but written as a separate function for purely technical reasons.

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
numerical(vulgar)

## S3 method for class 'fractional'
numerical(vulgar)

## S3 method for class 'charFrac'
numerical(vulgar)

## Default S3 method:
numerical(vulgar)

Arguments

vulgar

character string form of a class 'fractional' object.

Value

A numeric object as represented by its (usually fractional) display.

Methods (by class)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
suppressPackageStartupMessages(library(dplyr))
m <- 2*diag(5)
m[abs(row(m) - col(m)) == 1] <- -1
m  ## How much roundoff error does inverting entail?
(mi  <- solve(m) %>% fractional) ## patterned inverse
mi * max(denominators(mi)) ## clearer pattern
m1 <- solve(mi)
range(m1 - m)           ## roundoff still present
m2 <- m1 %>% numerical  ## remove roundoff error - hopefully!
identical(m2, m)        ## no roundoff

fractional documentation built on May 2, 2019, 4:16 a.m.