Convert a character vector to logical, integer, numeric, complex or factor as appropriate.
type.convert(x, na.strings = "NA", as.is = FALSE, dec = ".")
- a character vector.
- a vector of strings which are to be interpreted as
NAvalues. Blank fields are also considered to be missing values in logical, integer, numeric or complex vectors.
- logical. See ‘Details’.
- the character to be assumed for decimal points.
This is principally a helper function for
read.table. Given a character vector, it attempts to convert it to logical, integer, numeric or complex, and failing that converts it to factor unless
as.is = TRUE. The first type that can accept all the non-missing values is chosen (numeric and complex return values will represented approximately, of course).
Vectors which are entirely missing values are converted to logical, since
NA is primarily logical.
Vectors containing just
TRUE and values from
na.strings are converted to logical. Vectors containing optional whitespace followed by decimal constants representable as R integers or values from
na.strings are converted to integer. Other vectors containing optional whitespace followed by other decimal or hexadecimal constants (see NumericConstants), or
infinity (ignoring case) or values from
na.strings are converted to numeric.
Since this is a helper function, the caller should always pass an appropriate value of
A vector of the selected class, or a factor.
Documentation reproduced from R 3.0.1. License: GPL-2.