Types and Missing Values
Type Conversion
Text to Numbers
R values have types. Data often arrives as text, then gets converted before numeric functions can use it.
Program
Play the script to watch character values become numbers and then a total.
type_conversion.R
raw <- c("10", "12", "15")
numbers <- as.numeric(raw)
total <- sum(numbers)
cat(total, "\n", sep = "")
character vector
Quoted values such as `"10"` are text, even when they look numeric.
as.numeric
`as.numeric` converts compatible text values to numeric values.
type conversion
Conversion changes how later functions interpret the value.