Learn R Programming

extras (version 0.7.3)

numericise: Numericise (or Numericize)

Description

Coerce an R object to a numeric atomic object.

Usage

numericise(x, ...)

numericize(x, ...)

# S3 method for logical numericise(x, ...)

# S3 method for integer numericise(x, ...)

# S3 method for double numericise(x, ...)

# S3 method for factor numericise(x, ...)

# S3 method for Date numericise(x, ...)

# S3 method for POSIXct numericise(x, ...)

# S3 method for hms numericise(x, ...)

# S3 method for matrix numericise(x, ...)

# S3 method for array numericise(x, ...)

# S3 method for data.frame numericise(x, ...)

Value

A numeric atomic object.

Arguments

x

An object.

...

Other arguments passed to methods.

Methods (by class)

  • numericise(logical): Numericise a logical Object

  • numericise(integer): Numericise an integer Object

  • numericise(double): Numericise an double Object

  • numericise(factor): Numericise a factor

  • numericise(Date): Numericise a Date vector

  • numericise(POSIXct): Numericise a POSIXct vector

  • numericise(hms): Numericise a hms vector

  • numericise(matrix): Numericise a matrix

  • numericise(array): Numericise an array

  • numericise(data.frame): Numericise a data.frame

Details

numericize() is an alias for numericise. If you want to implement a method for a class "foo", implement numericise.foo().

Examples

Run this code

# logical
numericise(TRUE)
numericise(matrix(c(TRUE, FALSE), nrow = 2))

# integer
numericise(2L)

# double
numericise(c(1, 3))

# factor
numericise(factor(c("c", "a")))

# Date
numericise(as.Date("1972-01-01"))

# POSIXct
numericise(as.POSIXct("1972-01-01", tz = "UTC"))

# hms
numericise(hms::as_hms("00:01:03"))

# matrix
numericise(matrix(TRUE))

# array
numericise(array(TRUE))

# data.frame
numericise(data.frame(
  logical = c(TRUE, FALSE, NA),
  integer = 1:3,
  numeric = c(4, 10, NA),
  factor = as.factor(c("c", "A", "green"))
))

Run the code above in your browser using DataLab