AnyCompiler

Data Types

R's everyday types are numeric (double-precision floating point, R's default for plain numbers), integer (written with an L suffix, e.g. 5L), character (strings), and logical (TRUE/FALSE). class() tells you a value's high-level type; typeof() tells you its lower-level internal storage mode — they usually agree, but numeric and integer are where they visibly diverge.

print(class(5))
print(class(5L))
print(class("hello"))
print(class(TRUE))
print(class(NA))
print(typeof(5))
print(typeof(5L))
Output
[1] "numeric"
[1] "integer"
[1] "character"
[1] "logical"
[1] "logical"
[1] "double"
[1] "integer"

NA — R's representation of a missing value — reports its own class as "logical" by default, which is a quirk worth knowing: plain NA is the smallest, most generic form of missing value, and R silently upgrades it to match whatever type it ends up living inside a vector with.

Coercion and a real warning

as.numeric() tries to convert a value to a number. When the text genuinely isn't numeric, R doesn't stop your program — it produces NA and warns you about it. This is the real warning R produces, captured from a real run, not written to look plausible:

x <- as.numeric("abc")
print(x)
Output
[1] NA

stderr
Warning message:
NAs introduced by coercion

Your script kept running — x really does hold NA afterward, usable like any other value — but R made sure you'd see, in the output, that the conversion silently failed. This same pattern (keep going, but tell you something didn't fit) comes back later in the na-handling lesson. Next: vectorized operations — the single biggest R-vs-everything-else idea: arithmetic on a whole vector at once, with no loop.

Practice exercise

Print the class of 5L, then the class of "hello", then the class of TRUE, one per line.