Variables & Data Types

R has a handful of basic types — numeric, character, logical, integer — and class() tells you which one you're holding at any moment.

The basic types

R types.R
name <- "Ava"
age <- 29
is_student <- FALSE

class(name)
class(age)
class(is_student)
Console
[1] "character"
[1] "numeric"
[1] "logical"

Text is character, numbers default to numeric, and true/false values are logical — written in all capitals as TRUE and FALSE.

Numeric vs. integer

Every plain number in R, even a whole one like 5, is stored as numeric (a double-precision float) unless you explicitly mark it as an integer with a trailing L:

R integers.R
x <- 5
y <- 5L

class(x)
class(y)
Console
[1] "numeric"
[1] "integer"

In everyday R code this distinction rarely matters — most functions treat the two interchangeably — but it explains why class() sometimes reports "integer" for a value that looks identical to a "numeric" one.

NA: the missing value

NA represents a missing or unknown value, and it's contagious: almost any calculation that touches an NA becomes NA itself, rather than erroring or silently skipping it:

R na.R
score <- NA
score + 10
is.na(score)
Console
[1] NA
[1] TRUE
Note: NA spreading through a calculation is deliberate, not a bug — R is refusing to guess what a missing value should have been. The upcoming Basic Statistics lesson shows the standard way to tell a function to ignore NA values instead of propagating them.