Check if All Elements in Character Vector are Numeric
Check if All Elements in Character Vector are Numeric
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.
all.is.numeric(x, what = c("test","vector","nonnum"), 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, the default "test" to return FALSE if there are no non-missing non-extra values of x or there is at least one non-numeric value of x, or "nonnum" to return the vector of non-extra, non-NA, non-numeric values of x.
extras: a vector of character strings to count as numeric values, other than "".
Returns
a logical value if what="test" or a vector otherwise