Assignment and basic types

Assign values with <- or =. R has four atomic types: numeric, character, logical and integer. Use class() and typeof() to inspect, and is.* / as.* to test and coerce.

basics
# Assignment
x <- 42          # numeric
name <- "Alice"  # character
flag <- TRUE     # logical
n <- 5L          # integer

# Inspect type
class(x)         # "numeric"
typeof(flag)     # "logical"
is.numeric(x)    # TRUE
as.character(x)  # "42"

# Remove object
rm(x)
ls()             # list all objects in environment
# ── Example ──────────────────────────────────────────────────────
x    <- 3.14          # numeric
name <- "setosa"      # character
ok   <- TRUE          # logical
n    <- 5L            # integer (explicit)

class(x);  typeof(x)
class(ok); typeof(ok)

# Type coercion
as.numeric("42")
as.character(3.14)
as.logical(0)    # FALSE
as.logical(1)    # TRUE

# Check types
is.numeric(iris$Sepal.Length)   # TRUE
is.factor(iris$Species)          # TRUE