Learn R Programming

scrutiny (version 1.0.0)

is_numeric_like: Test whether a vector is numeric or coercible to numeric

Description

[Deprecated]

is_numeric_like() is deprecated because scrutiny no longer takes numbers as strings. It may be removed in a future version.

is_numeric_like() tests whether an object contains numbers, by scrutiny's standards:

  • Integer and double vectors are TRUE.

  • Logical vectors and non-vectors are FALSE.

  • Other vectors, such as strings, are TRUE if every non-NA value can be coerced to a non-NA number. The strings "NA" and "NaN" count as NA, and so does a blank string, as in a blank cell of a CSV file.

  • Factors, dates, and times are tested as the strings they print as.

  • Lists are tested like atomic vectors if every element has length 1, and are FALSE otherwise. A logical element other than NA makes a list FALSE.

  • A vector of nothing but non-numeric, non-logical NA is NA.

Usage

is_numeric_like(x)

Value

Logical (length 1).

Arguments

x

Object to be tested.

Details

It asks whether a vector displays numbers, not how it is stored.

Examples

Run this code
is_numeric_like(x = 1:5)
is_numeric_like(x = c(TRUE, FALSE))

is_numeric_like(x = c("42", "0.7", NA))
is_numeric_like(x = c("42", "xyz", NA))

is_numeric_like(x = as.factor(c("42", "0.7", NA)))

is_numeric_like(x = list("42", "0.7", NA))
is_numeric_like(x = list("42", "0.7", NA, c(1, 2, 3)))

# All `NA`:
is_numeric_like(x = as.character(c(NA, NA, NA)))
is_numeric_like(x = as.numeric(c(NA, NA, NA)))
is_numeric_like(x = c(NA, NA, NA))

Run the code above in your browser using DataLab