Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

all.is.numeric

Check if All Elements in Character Vector are Numeric


Description

Tests, without issuing warnings, whether all elements of a character vector are legal numeric values, or optionally converts the vector to a numeric vector. Leading and trailing blanks in x are ignored.

Usage

all.is.numeric(x, what = c("test", "vector"), extras=c('.','NA'))

Arguments

x

a character vector

what

specify what="vector" to return a numeric vector if it passes the test, or the original character vector otherwise

extras

a vector of character strings to count as numeric values, other than "".

Value

a logical value if what="test" or a vector otherwise

Author(s)

Frank Harrell

See Also

Examples

all.is.numeric(c('1','1.2','3'))
all.is.numeric(c('1','1.2','3a'))
all.is.numeric(c('1','1.2','3'),'vector')
all.is.numeric(c('1','1.2','3a'),'vector')
all.is.numeric(c('1','',' .'),'vector')

Hmisc

Harrell Miscellaneous

v4.5-0
GPL (>= 2)
Authors
Frank E Harrell Jr <fh@fharrell.com>, with contributions from Charles Dupont and many others.
Initial release
2021-02-27

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.