12.9 Be careful about the numeric type
- Often “numeric” is treated as synonymous for double:
# create a double and integeger objects
one <- 1
oneL <- 1L
typeof(one)
#> [1] "double"
typeof(oneL)
#> [1] "integer"
# check their type after as.numeric()
one |> as.numeric() |> typeof()
#> [1] "double"
oneL |> as.numeric() |> typeof()
#> [1] "double"
- In S3 and S4, “numeric” is taken as either integer or double, when choosing methods:
is.numeric()
tests whether an object behaves like a number
But Advanced R consistently uses numeric to mean integer or double type.